[clang] [clang-tools-extra] [lldb] [clang] implement CWG1980 and CWG2064: instantiation-dependency improvements (PR #190495)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 21 00:48:45 PDT 2026
================
@@ -6691,34 +6745,35 @@ QualType ASTContext::getReferenceQualifiedType(const Expr *E) const {
/// nodes. This would never be helpful, since each such type has its own
/// expression, and would not give a significant memory saving, since there
/// is an Expr tree under each such type.
-QualType ASTContext::getDecltypeType(Expr *E, QualType UnderlyingType) const {
- // C++11 [temp.type]p2:
- // If an expression e involves a template parameter, decltype(e) denotes a
- // unique dependent type. Two such decltype-specifiers refer to the same
- // type only if their expressions are equivalent (14.5.6.1).
- QualType CanonType;
- if (!E->isInstantiationDependent()) {
- CanonType = getCanonicalType(UnderlyingType);
- } else if (!UnderlyingType.isNull()) {
- CanonType = getDecltypeType(E, QualType());
- } else {
- llvm::FoldingSetNodeID ID;
- DependentDecltypeType::Profile(ID, *this, E);
+QualType ASTContext::getDecltypeType(Expr *E,
+ CanonicalizationKindOrNone ExprCanonKind,
+ QualType UnderlyingType) const {
+ llvm::FoldingSetNodeID ID;
+ DecltypeType::Profile(ID, *this, E, ExprCanonKind, UnderlyingType);
- void *InsertPos = nullptr;
- if (DependentDecltypeType *Canon =
- DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos))
- return QualType(Canon, 0);
+ void *InsertPos = nullptr;
+ if (auto *T = DecltypeTypes.FindNodeOrInsertPos(ID, InsertPos))
+ return QualType(T, 0);
- // Build a new, canonical decltype(expr) type.
- auto *DT =
- new (*this, alignof(DependentDecltypeType)) DependentDecltypeType(E);
- DependentDecltypeTypes.InsertNode(DT, InsertPos);
- Types.push_back(DT);
- return QualType(DT, 0);
+ // C++26 [temp.type]p4: If an expression e is type-dependent, decltype(e)
+ // denotes a unique dependent type. Two such decltype-specifiers refer to the
+ // same type only if their expressions are equivalent ([temp.over.link]).
+ QualType CanonType;
+ if (!E->isTypeDependent()) {
----------------
ojhunt wrote:
nit: no braces
https://github.com/llvm/llvm-project/pull/190495
More information about the cfe-commits
mailing list