[cfe-commits] r91395 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaTemplate.cpp test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
John McCall
rjmccall at apple.com
Mon Dec 14 18:19:47 PST 2009
Author: rjmccall
Date: Mon Dec 14 20:19:47 2009
New Revision: 91395
URL: http://llvm.org/viewvc/llvm-project?rev=91395&view=rev
Log:
Diagnose the use of typedefs for template specialization types in the scope
specifiers for out-of-line declarations, e.g.
typedef Temp<int> MyTemp;
template <> MyTemp::foo;
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=91395&r1=91394&r2=91395&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Dec 14 20:19:47 2009
@@ -971,6 +971,9 @@
def err_template_decl_ref : Error<
"cannot refer to class template %0 without a template argument list">;
+def err_typedef_in_def_scope : Error<
+ "cannot use typedef %0 in scope specifier for out-of-line declaration">;
+
// C++ Template Argument Lists
def err_template_arg_list_different_arity : Error<
"%select{too few|too many}0 template arguments for "
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=91395&r1=91394&r2=91395&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Dec 14 20:19:47 2009
@@ -1170,8 +1170,27 @@
ExplicitSpecializationsInSpecifier;
for (NestedNameSpecifier *NNS = (NestedNameSpecifier *)SS.getScopeRep();
NNS; NNS = NNS->getPrefix()) {
+ const Type *T = NNS->getAsType();
+ if (!T) break;
+
+ // C++0x [temp.expl.spec]p17:
+ // A member or a member template may be nested within many
+ // enclosing class templates. In an explicit specialization for
+ // such a member, the member declaration shall be preceded by a
+ // template<> for each enclosing class template that is
+ // explicitly specialized.
+ // We interpret this as forbidding typedefs of template
+ // specializations in the scope specifiers of out-of-line decls.
+ if (const TypedefType *TT = dyn_cast<TypedefType>(T)) {
+ const Type *UnderlyingT = TT->LookThroughTypedefs().getTypePtr();
+ if (isa<TemplateSpecializationType>(UnderlyingT))
+ // FIXME: better source location information.
+ Diag(DeclStartLoc, diag::err_typedef_in_def_scope) << QualType(T,0);
+ T = UnderlyingT;
+ }
+
if (const TemplateSpecializationType *SpecType
- = dyn_cast_or_null<TemplateSpecializationType>(NNS->getAsType())) {
+ = dyn_cast<TemplateSpecializationType>(T)) {
TemplateDecl *Template = SpecType->getTemplateName().getAsTemplateDecl();
if (!Template)
continue; // FIXME: should this be an error? probably...
Modified: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp?rev=91395&r1=91394&r2=91395&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp Mon Dec 14 20:19:47 2009
@@ -10,3 +10,15 @@
template<> template<> void A<char>::B<char>::mf();
template<> void A<char>::B<int>::mf(); // expected-error{{requires 'template<>'}}
+
+namespace test1 {
+ template <class> class A {
+ static int foo;
+ static int bar;
+ };
+ typedef A<int> AA;
+
+ template <> int AA::foo = 0; // expected-error {{cannot use typedef}}
+ int AA::bar = 1; // expected-error {{cannot use typedef}} expected-error {{template specialization requires 'template<>'}}
+ int A<float>::bar = 2; // expected-error {{template specialization requires 'template<>'}}
+}
More information about the cfe-commits
mailing list