[cfe-commits] r84156 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaTemplate.cpp

Douglas Gregor dgregor at apple.com
Wed Oct 14 16:50:59 PDT 2009


Author: dgregor
Date: Wed Oct 14 18:50:59 2009
New Revision: 84156

URL: http://llvm.org/viewvc/llvm-project?rev=84156&view=rev
Log:
CheckTemplateSpecializationScope isn't going to be used for explicit
instantiations, since the requirements are too different from those
for template specializations. Simplify it slightly.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=84156&r1=84155&r2=84156&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Oct 14 18:50:59 2009
@@ -936,18 +936,15 @@
 
 // C++ template specialization
 def err_template_spec_unknown_kind : Error<
-  "can only provide an explicit %select{<error>|<error>|specialization|"
-  "instantiation|instantiation}0 for a class template, function template, or "
-  "a member function, static data member, or member class of a class template">;
+  "can only provide an explicit specialization for a class template, function "
+  "template, or a member function, static data member, or member class of a "
+  "class template">;
 def note_specialized_entity : Note<
-  "explicitly %select{<error>|<error>|specialized|instantiated|instantiated}0 "
-  "declaration is here">;
+  "explicitly specialized declaration is here">;
 def err_template_spec_decl_function_scope : Error<
-  "explicit %select{<error>|<error>|specialization|instantiation|"
-  "instantiation}0 of %1 in function scope">;
+  "explicit specialization of %0 in function scope">;
 def err_template_spec_decl_class_scope : Error<
-  "explicit %select{<error>|<error>|specialization|instantiation|"
-  "instantiation}0 of %1 in class scope">;
+  "explicit specialization of %0 in class scope">;
 def err_template_spec_decl_out_of_scope_global : Error<
   "%select{class template|class template partial|function template|member "
   "function|static data member|member class}0 specialization of %1 must "

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=84156&r1=84155&r2=84156&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Oct 14 18:50:59 2009
@@ -2398,12 +2398,11 @@
   return TSK_Undeclared;
 }
 
-/// \brief Check whether a specialization or explicit instantiation is
-/// well-formed in the current context.
+/// \brief Check whether a specialization is well-formed in the current 
+/// context.
 ///
-/// This routine determines whether a template specialization or
-/// explicit instantiation can be declared in the current context
-/// (C++ [temp.expl.spec]p2, C++0x [temp.explicit]p2).
+/// This routine determines whether a template specialization can be declared
+/// in the current context (C++ [temp.expl.spec]p2).
 ///
 /// \param S the semantic analysis object for which this check is being
 /// performed.
@@ -2421,17 +2420,13 @@
 /// \param IsPartialSpecialization whether this is a partial specialization of
 /// a class template.
 ///
-/// \param TSK the kind of specialization or explicit instantiation being 
-/// performed.
-///
 /// \returns true if there was an error that we cannot recover from, false
 /// otherwise.
 static bool CheckTemplateSpecializationScope(Sema &S,
                                              NamedDecl *Specialized,
                                              NamedDecl *PrevDecl,
                                              SourceLocation Loc,
-                                             bool IsPartialSpecialization,
-                                             TemplateSpecializationKind TSK) {
+                                             bool IsPartialSpecialization) {
   // Keep these "kind" numbers in sync with the %select statements in the
   // various diagnostics emitted by this routine.
   int EntityKind = 0;
@@ -2449,8 +2444,8 @@
   else if (isa<RecordDecl>(Specialized))
     EntityKind = 5;
   else {
-    S.Diag(Loc, diag::err_template_spec_unknown_kind) << TSK;
-    S.Diag(Specialized->getLocation(), diag::note_specialized_entity) << TSK;
+    S.Diag(Loc, diag::err_template_spec_unknown_kind);
+    S.Diag(Specialized->getLocation(), diag::note_specialized_entity);
     return true;
   }
 
@@ -2469,13 +2464,13 @@
   //   declared.
   if (S.CurContext->getLookupContext()->isFunctionOrMethod()) {
     S.Diag(Loc, diag::err_template_spec_decl_function_scope)
-      << TSK << Specialized;
+      << Specialized;
     return true;
   }
 
   if (S.CurContext->isRecord() && !IsPartialSpecialization) {
     S.Diag(Loc, diag::err_template_spec_decl_class_scope)
-      << TSK << Specialized;
+      << Specialized;
     return true;
   }
   
@@ -2487,43 +2482,36 @@
   DeclContext *SpecializedContext 
     = Specialized->getDeclContext()->getEnclosingNamespaceContext();
   DeclContext *DC = S.CurContext->getEnclosingNamespaceContext();
-  if (TSK == TSK_ExplicitSpecialization) {
-    if ((!PrevDecl || 
-         getTemplateSpecializationKind(PrevDecl) == TSK_Undeclared ||
-         getTemplateSpecializationKind(PrevDecl) == TSK_ImplicitInstantiation)){
-      // There is no prior declaration of this entity, so this
-      // specialization must be in the same context as the template
-      // itself.
-      if (!DC->Equals(SpecializedContext)) {
-        if (isa<TranslationUnitDecl>(SpecializedContext))
-          S.Diag(Loc, diag::err_template_spec_decl_out_of_scope_global)
-          << EntityKind << Specialized;
-        else if (isa<NamespaceDecl>(SpecializedContext))
-          S.Diag(Loc, diag::err_template_spec_decl_out_of_scope)
-          << EntityKind << Specialized
-          << cast<NamedDecl>(SpecializedContext);
-        
-        S.Diag(Specialized->getLocation(), diag::note_specialized_entity) 
-          << TSK;
-        ComplainedAboutScope = true;
-      }
+  if ((!PrevDecl || 
+       getTemplateSpecializationKind(PrevDecl) == TSK_Undeclared ||
+       getTemplateSpecializationKind(PrevDecl) == TSK_ImplicitInstantiation)){
+    // There is no prior declaration of this entity, so this
+    // specialization must be in the same context as the template
+    // itself.
+    if (!DC->Equals(SpecializedContext)) {
+      if (isa<TranslationUnitDecl>(SpecializedContext))
+        S.Diag(Loc, diag::err_template_spec_decl_out_of_scope_global)
+        << EntityKind << Specialized;
+      else if (isa<NamespaceDecl>(SpecializedContext))
+        S.Diag(Loc, diag::err_template_spec_decl_out_of_scope)
+        << EntityKind << Specialized
+        << cast<NamedDecl>(SpecializedContext);
+      
+      S.Diag(Specialized->getLocation(), diag::note_specialized_entity);
+      ComplainedAboutScope = true;
     }
   }
   
   // Make sure that this redeclaration (or definition) occurs in an enclosing 
-  // namespace. We perform this check for explicit specializations and, in 
-  // C++0x, for explicit instantiations as well (per DR275).
-  // FIXME: -Wc++0x should make these warnings.
+  // namespace.
   // Note that HandleDeclarator() performs this check for explicit 
   // specializations of function templates, static data members, and member
   // functions, so we skip the check here for those kinds of entities.
   // FIXME: HandleDeclarator's diagnostics aren't quite as good, though.
   // Should we refactor that check, so that it occurs later?
   if (!ComplainedAboutScope && !DC->Encloses(SpecializedContext) &&
-      ((TSK == TSK_ExplicitSpecialization &&
-        !(isa<FunctionTemplateDecl>(Specialized) || isa<VarDecl>(Specialized) ||
-          isa<FunctionDecl>(Specialized))) || 
-        S.getLangOptions().CPlusPlus0x)) {
+      !(isa<FunctionTemplateDecl>(Specialized) || isa<VarDecl>(Specialized) ||
+        isa<FunctionDecl>(Specialized))) {
     if (isa<TranslationUnitDecl>(SpecializedContext))
       S.Diag(Loc, diag::err_template_spec_redecl_global_scope)
         << EntityKind << Specialized;
@@ -2532,7 +2520,7 @@
         << EntityKind << Specialized
         << cast<NamedDecl>(SpecializedContext);
   
-    S.Diag(Specialized->getLocation(), diag::note_specialized_entity) << TSK;
+    S.Diag(Specialized->getLocation(), diag::note_specialized_entity);
   }
   
   // FIXME: check for specialization-after-instantiation errors and such.
@@ -2835,8 +2823,8 @@
   // the current scope.
   if (TUK != TUK_Friend &&
       CheckTemplateSpecializationScope(*this, ClassTemplate, PrevDecl, 
-                                       TemplateNameLoc, isPartialSpecialization,
-                                       TSK_ExplicitSpecialization))
+                                       TemplateNameLoc, 
+                                       isPartialSpecialization))
     return true;
   
   // The canonical type
@@ -3146,7 +3134,7 @@
   if (CheckTemplateSpecializationScope(*this, 
                                        Specialization->getPrimaryTemplate(),
                                        Specialization, FD->getLocation(), 
-                                       false, TSK_ExplicitSpecialization))
+                                       false))
     return true;
 
   // C++ [temp.expl.spec]p6:
@@ -3273,7 +3261,7 @@
   if (CheckTemplateSpecializationScope(*this, 
                                        InstantiatedFrom,
                                        Instantiation, Member->getLocation(), 
-                                       false, TSK_ExplicitSpecialization))
+                                       false))
     return true;
 
   // Note that this is an explicit instantiation of a member.





More information about the cfe-commits mailing list