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

John McCall rjmccall at apple.com
Tue Mar 2 15:09:38 PST 2010


Author: rjmccall
Date: Tue Mar  2 17:09:38 2010
New Revision: 97605

URL: http://llvm.org/viewvc/llvm-project?rev=97605&view=rev
Log:
Suppress implicit member redeclarations arising from explicit instantiation
declarations after the member has been explicitly specialized.  We already
did this after explicit instantiation definitions;  not doing it for
declarations meant that subsequent definitions would see a previous
member declaration with specialization kind "explicit instantiation decl",
which would then happily get overridden.

Fixes PR 6458.


Modified:
    cfe/trunk/lib/Sema/SemaTemplate.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=97605&r1=97604&r2=97605&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Mar  2 17:09:38 2010
@@ -3790,6 +3790,7 @@
       //   of a template appears after a declaration of an explicit 
       //   specialization for that template, the explicit instantiation has no
       //   effect.
+      SuppressNew = true;
       return false;
         
     case TSK_ExplicitInstantiationDefinition:

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=97605&r1=97604&r2=97605&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 Tue Mar  2 17:09:38 2010
@@ -30,3 +30,19 @@
 
 template<> struct X0<double>;
 template struct X0<double>;
+
+// PR 6458
+namespace test0 {
+  template <class T> class foo {
+    int compare(T x, T y);
+  };
+
+  template <> int foo<char>::compare(char x, char y);
+  template <class T> int foo<T>::compare(T x, T y) {
+    // invalid at T=char; if we get a diagnostic here, we're
+    // inappropriately instantiating this template.
+    void *ptr = x;
+  }
+  extern template class foo<char>;
+  template class foo<char>;
+}





More information about the cfe-commits mailing list