Skip to content

Commit 06721bb

Browse files
authored
[clang] implement common sugared type of inst-dependent DecltypeType (#67739)
While a DecltypeType node itself is not uniqued, an instantiation dependent DecltypeType will have a DependentDecltypeType as an underlying type, which is uniqued. In that case, there can be non-identical non-sugar DecltypeTypes nodes which nonetheless represent the same type. Fixes #67603
1 parent 3686a0b commit 06721bb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ Bug Fixes in This Version
266266
(`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
267267
- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
268268
(`#65557 <https://github.com/llvm/llvm-project/issues/65557>`_)
269+
- Fixes crash when trying to obtain the common sugared type of
270+
`decltype(instantiation-dependent-expr)`.
271+
Fixes (`#67603 <https://github.com/llvm/llvm-project/issues/67603>`_)
269272

270273
Bug Fixes to Compiler Builtins
271274
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ASTContext.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12705,7 +12705,6 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1270512705

1270612706
#define SUGAR_FREE_TYPE(Class) UNEXPECTED_TYPE(Class, "sugar-free")
1270712707
SUGAR_FREE_TYPE(Builtin)
12708-
SUGAR_FREE_TYPE(Decltype)
1270912708
SUGAR_FREE_TYPE(DeducedTemplateSpecialization)
1271012709
SUGAR_FREE_TYPE(DependentBitInt)
1271112710
SUGAR_FREE_TYPE(Enum)
@@ -12935,6 +12934,14 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1293512934
TY->getTemplateName()),
1293612935
As, X->getCanonicalTypeInternal());
1293712936
}
12937+
case Type::Decltype: {
12938+
const auto *DX = cast<DecltypeType>(X), *DY = cast<DecltypeType>(Y);
12939+
assert(DX->isDependentType());
12940+
assert(DY->isDependentType());
12941+
assert(Ctx.hasSameExpr(DX->getUnderlyingExpr(), DY->getUnderlyingExpr()));
12942+
// As Decltype is not uniqued, building a common type would be wasteful.
12943+
return QualType(DX, 0);
12944+
}
1293812945
case Type::DependentName: {
1293912946
const auto *NX = cast<DependentNameType>(X),
1294012947
*NY = cast<DependentNameType>(Y);

clang/test/SemaCXX/sugar-common-types.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,14 @@ namespace PR61419 {
142142
extern const pair<id, id> p;
143143
id t = false ? p.first : p.second;
144144
} // namespace PR61419
145+
146+
namespace GH67603 {
147+
template <class> using A = long;
148+
template <class B> void h() {
149+
using C = B;
150+
using D = B;
151+
N t = 0 ? A<decltype(C())>() : A<decltype(D())>();
152+
// expected-error@-1 {{rvalue of type 'A<decltype(C())>' (aka 'long')}}
153+
}
154+
template void h<int>();
155+
} // namespace GH67603

0 commit comments

Comments
 (0)