[cfe-commits] r142588 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/class-template-spec.cpp

Douglas Gregor dgregor at apple.com
Thu Oct 20 09:41:18 PDT 2011


Author: dgregor
Date: Thu Oct 20 11:41:18 2011
New Revision: 142588

URL: http://llvm.org/viewvc/llvm-project?rev=142588&view=rev
Log:
Diagnose class template (partial) specializations that occur in the
*wrong* class scope. This is one of the problems behind
<rdar://problem/9676205>.

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/class-template-spec.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=142588&r1=142587&r2=142588&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Oct 20 11:41:18 2011
@@ -4565,12 +4565,21 @@
     }
   }
 
+  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 ||

Modified: cfe/trunk/test/SemaTemplate/class-template-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/class-template-spec.cpp?rev=142588&r1=142587&r2=142588&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/class-template-spec.cpp (original)
+++ cfe/trunk/test/SemaTemplate/class-template-spec.cpp Thu Oct 20 11:41:18 2011
@@ -109,3 +109,13 @@
 // 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}}
+    };
+  };
+
+}





More information about the cfe-commits mailing list