[cfe-commits] r100900 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiate.cpp test/CXX/temp/temp.spec/temp.explicit/p4.cpp

Douglas Gregor dgregor at apple.com
Fri Apr 9 14:02:29 PDT 2010


Author: dgregor
Date: Fri Apr  9 16:02:29 2010
New Revision: 100900

URL: http://llvm.org/viewvc/llvm-project?rev=100900&view=rev
Log:
Only complain about explicit instantiations following explicit
specializations when the explicit instantiation was... explicitly
written, i.e., not the product of an explicit instantiation of an
enclosing class. Fixes this spurious warning when Clang builds LLVM:

/Volumes/Data/dgregor/Projects/llvm/lib/CodeGen/MachineDominators.cpp:22:1:
warning: explicit instantiation of 'addRoot' that occurs after an
explicit specialization will be ignored (C++0x extension) [-pedantic]


Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p4.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=100900&r1=100899&r2=100900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Apr  9 16:02:29 2010
@@ -4047,7 +4047,7 @@
       //   instantiation has no effect.
       //
       // In C++98/03 mode, we only give an extension warning here, because it 
-      // is not not harmful to try to explicitly instantiate something that
+      // is not harmful to try to explicitly instantiate something that
       // has been explicitly specialized.
       if (!getLangOptions().CPlusPlus0x) {
         Diag(NewLoc, diag::ext_explicit_instantiation_after_specialization)
@@ -4204,6 +4204,7 @@
 
   // Ignore access information;  it doesn't figure into redeclaration checking.
   FunctionDecl *Specialization = cast<FunctionDecl>(*Result);
+  Specialization->setLocation(FD->getLocation());
   
   // FIXME: Check if the prior specialization has a point of instantiation.
   // If so, we have run afoul of .

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=100900&r1=100899&r2=100900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Fri Apr  9 16:02:29 2010
@@ -1381,6 +1381,10 @@
         MemberSpecializationInfo *MSInfo 
           = Function->getMemberSpecializationInfo();
         assert(MSInfo && "No member specialization information?");
+        if (MSInfo->getTemplateSpecializationKind()
+                                                 == TSK_ExplicitSpecialization)
+          continue;
+        
         if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, 
                                                    Function, 
                                         MSInfo->getTemplateSpecializationKind(),
@@ -1413,6 +1417,10 @@
       if (Var->isStaticDataMember()) {
         MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo();
         assert(MSInfo && "No member specialization information?");
+        if (MSInfo->getTemplateSpecializationKind()
+                                                 == TSK_ExplicitSpecialization)
+          continue;
+        
         if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, 
                                                    Var, 
                                         MSInfo->getTemplateSpecializationKind(),
@@ -1444,6 +1452,11 @@
       
       MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo();
       assert(MSInfo && "No member specialization information?");
+      
+      if (MSInfo->getTemplateSpecializationKind()
+                                                == TSK_ExplicitSpecialization)
+        continue;
+      
       if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, 
                                                  Record, 
                                         MSInfo->getTemplateSpecializationKind(),

Modified: cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p4.cpp?rev=100900&r1=100899&r2=100900&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p4.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p4.cpp Fri Apr  9 16:02:29 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 
 template<typename T> void f0(T); // expected-note{{here}}
 template void f0(int); // expected-error{{explicit instantiation of undefined function template}}
@@ -16,20 +16,20 @@
 
 template int X0<int>::value; // expected-error{{explicit instantiation of undefined static data member}}
 
-template<> void f0(long);
-template void f0(long); // okay
+template<> void f0(long); // expected-note{{previous template specialization is here}}
+template void f0(long); // expected-warning{{explicit instantiation of 'f0<long>' that occurs after an explicit specialization will be ignored}}
 
-template<> void X0<long>::f1();
-template void X0<long>::f1();
+template<> void X0<long>::f1(); // expected-note{{previous template specialization is here}}
+template void X0<long>::f1(); // expected-warning{{explicit instantiation of 'f1' that occurs after an explicit specialization will be ignored}}
 
-template<> struct X0<long>::Inner;
-template struct X0<long>::Inner;
+template<> struct X0<long>::Inner; // expected-note{{previous template specialization is here}}
+template struct X0<long>::Inner; // expected-warning{{explicit instantiation of 'Inner' that occurs after an explicit specialization will be ignored}}
 
-template<> long X0<long>::value;
-template long X0<long>::value;
+template<> long X0<long>::value; // expected-note{{previous template specialization is here}}
+template long X0<long>::value; // expected-warning{{explicit instantiation of 'value' that occurs after an explicit specialization will be ignored}}
 
-template<> struct X0<double>;
-template struct X0<double>;
+template<> struct X0<double>; // expected-note{{previous template specialization is here}}
+template struct X0<double>; // expected-warning{{explicit instantiation of 'X0<double>' that occurs after an explicit specialization will be ignored}}
 
 // PR 6458
 namespace test0 {





More information about the cfe-commits mailing list