diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-04 03:18:57 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-04 03:18:57 +0000 |
| commit | 9a94d9b876acd67f4476cecc5f26fd6c9f39b4b8 (patch) | |
| tree | 6ff72409949e5f5ddefe1b2ce5f93c2d689cdc1b | |
| parent | a95069c52fb4a4e7492252b8cbb8765e621d485c (diff) | |
| download | bcm5719-llvm-9a94d9b876acd67f4476cecc5f26fd6c9f39b4b8.tar.gz bcm5719-llvm-9a94d9b876acd67f4476cecc5f26fd6c9f39b4b8.zip | |
Don't instantiate members not belonging in the semantic context of the template.
e.g. for:
template <int i> class A {
class B *g;
};
'class B' has the template as lexical context but semantically it is
introduced in namespace scope.
Fixes rdar://8611125 & http://llvm.org/PR8505
llvm-svn: 118235
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 12 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/template-instantiation.cpp | 13 |
2 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 71235d92851..f78fe81aa8b 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1223,6 +1223,18 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), MemberEnd = Pattern->decls_end(); Member != MemberEnd; ++Member) { + // Don't instantiate members not belonging in this semantic context. + // e.g. for: + // @code + // template <int i> class A { + // class B *g; + // }; + // @endcode + // 'class B' has the template as lexical context but semantically it is + // introduced in namespace scope. + if ((*Member)->getDeclContext() != Pattern) + continue; + Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs); if (NewMember) { if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) diff --git a/clang/test/CodeGenCXX/template-instantiation.cpp b/clang/test/CodeGenCXX/template-instantiation.cpp index a8729035e28..0df2e23c70c 100644 --- a/clang/test/CodeGenCXX/template-instantiation.cpp +++ b/clang/test/CodeGenCXX/template-instantiation.cpp @@ -109,3 +109,16 @@ namespace test4 { A<int>::foo(); } } + +namespace PR8505 { +// Hits an assertion due to bogus instantiation of class B. +template <int i> class A { + class B* g; +}; +class B { + void f () {} +}; +// Should not instantiate class B since it is introduced in namespace scope. +// CHECK-NOT: _ZN6PR85051AILi0EE1B1fEv +template class A<0>; +} |

