[clang] [Clang][RFC] Resugar attributed type alias (PR #143143)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 6 07:15:06 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:
Otherwise, passing that second 'Underlying' argument would be unnecessary.
The reason we have that second parameter is to support a feature called 'divergent typedefs', which was added a couple of years ago in order to make resugaring more efficient.
This is currently used by the getCommonSugaredType infrastructure as well.
But yeah, this allows you to invent a different underlying type for a TypedefType, without having to create a fake TypedefDecl for it.
https://github.com/llvm/llvm-project/pull/143143
More information about the cfe-commits
mailing list