summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-10-20 16:41:18 +0000
committerDouglas Gregor <dgregor@apple.com>2011-10-20 16:41:18 +0000
commit44e5a0a72b778627d8be3cd45340024c003666ac (patch)
tree150f6d92fa6cd8b3586177ab7e7ae6cd81f82614 /clang
parentf65d8ffca7b2ffe6227b91e82e4f40f2d0c09c75 (diff)
downloadbcm5719-llvm-44e5a0a72b778627d8be3cd45340024c003666ac.tar.gz
bcm5719-llvm-44e5a0a72b778627d8be3cd45340024c003666ac.zip
Diagnose class template (partial) specializations that occur in the
*wrong* class scope. This is one of the problems behind <rdar://problem/9676205>. llvm-svn: 142588
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp11
-rw-r--r--clang/test/SemaTemplate/class-template-spec.cpp10
2 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 00cc9b53b6d..8bfcde60920 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4565,12 +4565,21 @@ static bool CheckTemplateSpecializationScope(Sema &S,
}
}
+ if (S.CurContext->isRecord() &&
+ !S.CurContext->Equals(Specialized->getDeclContext())) {
+ // Make sure that we're specializing in the right record context.
+ // Otherwise, things can go horribly wrong.
+ S.Diag(Loc, diag::err_template_spec_decl_class_scope)
+ << Specialized;
+ return true;
+ }
+
// C++ [temp.class.spec]p6:
// A class template partial specialization may be declared or redeclared
// in any namespace scope in which its definition may be defined (14.5.1
// and 14.5.2).
bool ComplainedAboutScope = false;
- DeclContext *SpecializedContext
+ DeclContext *SpecializedContext
= Specialized->getDeclContext()->getEnclosingNamespaceContext();
DeclContext *DC = S.CurContext->getEnclosingNamespaceContext();
if ((!PrevDecl ||
diff --git a/clang/test/SemaTemplate/class-template-spec.cpp b/clang/test/SemaTemplate/class-template-spec.cpp
index 07a5e2982c7..8213a726359 100644
--- a/clang/test/SemaTemplate/class-template-spec.cpp
+++ b/clang/test/SemaTemplate/class-template-spec.cpp
@@ -109,3 +109,13 @@ Foo<int> x;
// Template template parameters
template<template<class T> class Wibble>
class Wibble<int> { }; // expected-error{{cannot specialize a template template parameter}}
+
+namespace rdar9676205 {
+ template<typename T>
+ struct X {
+ template<typename U>
+ struct X<U*> { // expected-error{{explicit specialization of 'X' in class scope}}
+ };
+ };
+
+}
OpenPOWER on IntegriCloud