diff options
author | Bung <crc32@qq.com> | 2022-12-23 16:47:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-23 09:47:01 +0100 |
commit | 13251c2ac9c7e76fb506eeb686a5e5d19d67d0de (patch) | |
tree | 637edb1646cb9c334bd9f937d4dba6623ce4275d | |
parent | 3bba2b34fd632a4c01a6eb0e6f13d4e3a20bf104 (diff) | |
download | Nim-13251c2ac9c7e76fb506eeb686a5e5d19d67d0de.tar.gz |
fix #12946 Bad C++ codegen on distinct generics C++ types (#21157)
-rw-r--r-- | compiler/ccgtypes.nim | 9 | ||||
-rw-r--r-- | tests/cpp/t12946.nim | 4 |
2 files changed, 9 insertions, 4 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 3c9f9d923..e7677f2f2 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -826,7 +826,8 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin m.s[cfsTypes].addf("typedef $1 $2[$3];$n", [foo, result, rope(n)]) of tyObject, tyTuple: - if isImportedCppType(t) and origTyp.kind == tyGenericInst: + let tt = origTyp.skipTypes({tyDistinct}) + if isImportedCppType(t) and tt.kind == tyGenericInst: let cppNameAsRope = getTypeName(m, t, sig) let cppName = $cppNameAsRope var i = 0 @@ -849,7 +850,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin result.add cppName.substr(chunkStart, chunkEnd) chunkStart = i - let typeInSlot = resolveStarsInCppType(origTyp, idx + 1, stars) + let typeInSlot = resolveStarsInCppType(tt, idx + 1, stars) addResultType(typeInSlot) else: inc i @@ -858,9 +859,9 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin result.add cppName.substr(chunkStart) else: result = cppNameAsRope & "<" - for i in 1..<origTyp.len-1: + for i in 1..<tt.len-1: if i > 1: result.add(" COMMA ") - addResultType(origTyp[i]) + addResultType(tt[i]) result.add("> ") # always call for sideeffects: assert t.kind != tyTuple diff --git a/tests/cpp/t12946.nim b/tests/cpp/t12946.nim new file mode 100644 index 000000000..cf6bf5cfc --- /dev/null +++ b/tests/cpp/t12946.nim @@ -0,0 +1,4 @@ +import std/atomics +type Futex = distinct Atomic[int32] + +var x: Futex |