[clang] [Clang][P1061] Fix template arguments in local classes (PR #121225)
Jason Rice via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 11 10:48:42 PDT 2025
================
@@ -4433,8 +4433,12 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
// No need to instantiate in-class initializers during explicit
// instantiation.
if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
+ // Handle local classes which could have substituted template params.
CXXRecordDecl *ClassPattern =
- Instantiation->getTemplateInstantiationPattern();
+ Instantiation->isLocalClass()
+ ? Instantiation->getInstantiatedFromMemberClass()
+ : Instantiation->getTemplateInstantiationPattern();
----------------
ricejasonf wrote:
The comments for that states
```cpp
/// Retrieve the record declaration from which this record could be
/// instantiated. Returns null if this class is not a template instantiation.
const CXXRecordDecl *getTemplateInstantiationPattern() const;
```
So the "pattern" as I read it, is not an instantiation itself but the template (or partial specialization). In the case of the field in `struct L` we need the intermediate instantiated struct to get the instantiated field.
https://github.com/llvm/llvm-project/pull/121225
More information about the cfe-commits
mailing list