[PATCH] D112765: [AST] injected-class-name is not a redecl, even in template specializations
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 29 09:15:50 PDT 2021
sammccall added inline comments.
================
Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:1841-1842
+ /*DelayTypeCreation=*/IsInjectedClassName);
+ if (IsInjectedClassName)
+ SemaRef.Context.getTypeDeclType(Record, cast<CXXRecordDecl>(Owner));
----------------
hokein wrote:
> aaron.ballman wrote:
> > Why is this call needed? (It seems strange to me that we call it and ignore the return value.)
> my understanding is
> - `getTypeDeclType` is more than a getter, it also has a side-effort -- if the type of the passed `Record` is empty, it creates a type, and propagates the type to `Record->TypeForDecl`;
> - from the above line, we delay the type creation when `IsInjectedClassName` is true;
> - so we need to create a type for the `Record` by invoking `getTypeDeclType`;
>
> might be worth a comment.
>
That's exactly right. The injected-class-name is an independent decl but yields the same RecordType, and getTypeDeclType has a hacky interface so we can force this link.
(It wasn't needed in the old version of the code, because when it was a redecl getTypeDeclType would yield the same type in any case)
I should have mentioned this is all derived from the injected-class-name handling in Sema::ActOnStartCXXMemberDeclarations(). It lacks comments, but I'll add a few while here.
================
Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:1910
+ if (IsInjectedClassName)
+ assert(Record->isInjectedClassName() && "Broken injected-class-name");
----------------
hokein wrote:
> it is unclear to me what's the intention of the assertion.
We needed to do a few weird things (and to assume some things about the input) to initialize the injected-class-name, it verifies we got them all right.
(This assertion is also in ActOnStartCXXMemberDeclarations())
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112765/new/
https://reviews.llvm.org/D112765
More information about the cfe-commits
mailing list