[clang] [clang][NFC] Remove ASTContext::Types (PR #246322)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 1 09:04:02 PST 2026


================
@@ -1019,32 +1019,23 @@ ASTContext::setExternalSource(IntrusiveRefCntPtr<ExternalASTSource> Source) {
   ExternalSource = std::move(Source);
 }
 
+void ASTContext::addType(Type *T) const {
----------------
AaronBallman wrote:

I'm a bit worried about how easy it will be to forget to call `addType()` and just return a `QualType` directly from any new ASTContext interfaces we add; would it make sense to make this responsible for handling all of the various lists and returning the `QualType` itself? e.g.,
```
QualType ASTContext::createCanonicalTypeDefinition(Type *T) const {
 ++NumTypes[T->getTypeClass()];
  if (isa<RecordType, InjectedClassNameType>(T))
    RecordTypes.push_back(T);
  else if (isa<LValueReferenceType>(T))
    LValueReferenceTypes.insert(T);
  ...
  return QualType{T, 0};
}
```
and have callers do `return createCanonicalTypeDefinition(SomeType);`? without having to worry about which list to add the type to?

(I don't insist on going this route, mostly just wondering if the design can be improved some more.)

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


More information about the cfe-commits mailing list