[clang] [Clang][RFC] Resugar attributed type alias (PR #143143)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 6 07:46:20 PDT 2025


================
@@ -6998,6 +7007,31 @@ namespace {
         else
           return C.getRValueReferenceType(New);
       }
+      case Elaborated: {
+        auto *ET = cast<ElaboratedType>(Old);
+        return C.getElaboratedType(ET->getKeyword(), ET->getQualifier(),
+                                   wrap(C, ET->getNamedType(), I));
+      }
+      case TypeAlias: {
+        auto *ET = cast<TypedefType>(Old);
+        QualType Underlying = wrap(C, ET->desugar(), I);
+        TypedefNameDecl *Typedef;
+        if (auto *TD = dyn_cast<TypedefDecl>(ET->getDecl())) {
+          Typedef = TypedefDecl::Create(C, TD->getDeclContext(),
+                                        TD->getBeginLoc(), TD->getLocation(),
+                                        TD->getIdentifier(), nullptr);
+          Typedef->setModedTypeSourceInfo(TD->getTypeSourceInfo(), Underlying);
+        } else {
+          auto *Alias = cast<TypeAliasDecl>(ET->getDecl());
+          Typedef = TypedefDecl::Create(
+              C, Alias->getDeclContext(), Alias->getBeginLoc(),
+              Alias->getLocation(), Alias->getIdentifier(), nullptr);
+          Typedef->setModedTypeSourceInfo(Alias->getTypeSourceInfo(),
+                                          Underlying);
+        }
+        Typedef->setPreviousDecl(ET->getDecl());
+        return C.getTypedefType(Typedef, Underlying);
----------------
mizvekov wrote:

In both cases, either divergent typedef or creating a new decl, if the types are not the same, you have to deal with these consequences.

For example, getCommonSugaredType expects all TypedefTypes of the same typedef declaration to be the same type. 

https://github.com/llvm/llvm-project/pull/143143


More information about the cfe-commits mailing list