[clang] [Clang][RFC] Resugar attributed type alias (PR #143143)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 6 07:25:30 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);
----------------
zyn0217 wrote:
> But yeah, this allows you to invent a different underlying type for a TypedefType, without having to create a fake TypedefDecl for it.
No? There's an assert in that function:
assert(hasSameType(Decl->getUnderlyingType(), Underlying));
https://github.com/llvm/llvm-project/pull/143143
More information about the cfe-commits
mailing list