Skip to content

Commit 5be8b4b

Browse files
committed
[Clang][P1061] Fix template arguments in local classes
1 parent 00311cf commit 5be8b4b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ Bug Fixes to C++ Support
955955
consistently treat the initializer as manifestly constant-evaluated.
956956
(#GH135281)
957957
- Fix a crash in the presence of invalid base classes. (#GH147186)
958+
- Fix a crash with NTTP when instantiating local class.
958959

959960
Bug Fixes to AST Handling
960961
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4412,8 +4412,12 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
44124412
// No need to instantiate in-class initializers during explicit
44134413
// instantiation.
44144414
if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
4415+
// Handle local classes which could have substituted template params.
44154416
CXXRecordDecl *ClassPattern =
4416-
Instantiation->getTemplateInstantiationPattern();
4417+
Instantiation->isLocalClass()
4418+
? Instantiation->getInstantiatedFromMemberClass()
4419+
: Instantiation->getTemplateInstantiationPattern();
4420+
44174421
DeclContext::lookup_result Lookup =
44184422
ClassPattern->lookup(Field->getDeclName());
44194423
FieldDecl *Pattern = Lookup.find_first<FieldDecl>();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -fsyntax-only %s -verify
2+
// expected-no-diagnostics
3+
4+
template <int i>
5+
int g() {
6+
return [] (auto) -> int {
7+
struct L {
8+
int m = i;
9+
};
10+
return 0;
11+
} (42);
12+
}
13+
14+
int v = g<1>();

0 commit comments

Comments
 (0)