PR c++/14622
authorsimartin <simartin@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 Feb 2007 22:17:06 +0000 (22:17 +0000)
committersimartin <simartin@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 Feb 2007 22:17:06 +0000 (22:17 +0000)
* pt.c (do_decl_instantiation): Detect type mismatches in explicit
instantiations for variables.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121864 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/instantiate9.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C

index 95bcd26..b7d5973 100644 (file)
@@ -1,3 +1,10 @@
+2007-02-12  Simon Martin  <simartin@users.sourceforge.net>
+           Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/14622
+       * pt.c (do_decl_instantiation): Detect type mismatches in explicit
+       instantiations for variables.
+
 2007-02-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR middle-end/7651
index 078d433..ee8db6d 100644 (file)
@@ -11728,6 +11728,13 @@ do_decl_instantiation (tree decl, tree storage)
          error ("no matching template for %qD found", decl);
          return;
        }
+      if (!same_type_p (TREE_TYPE (result), TREE_TYPE (decl)))
+       {
+         error ("type %qT for explicit instantiation %qD does not match "
+                "declared type %qT", TREE_TYPE (result), decl,
+                TREE_TYPE (decl));
+         return;
+       }
     }
   else if (TREE_CODE (decl) != FUNCTION_DECL)
     {
index a2edb27..60e00e2 100644 (file)
@@ -1,3 +1,10 @@
+2007-02-12  Simon Martin  <simartin@users.sourceforge.net>
+
+       PR c++/14622
+       * g++.dg/template/instantiate9.C: New test.
+       * g++.old-deja/g++.pt/instantiate12.C: Fixed type mismatches in explicit
+       instantiations.
+
 2007-02-12  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.target/i386/parity-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/template/instantiate9.C b/gcc/testsuite/g++.dg/template/instantiate9.C
new file mode 100644 (file)
index 0000000..20fefaf
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR c++/14622. The invalid explicit instantiation was not reported. */
+/* { dg-do "compile" } */
+template<class T>
+class A
+{
+  static T a;
+};
+
+template<class T>
+T A<T>::a;
+
+struct B {};
+
+template B A<int>::a; /* { dg-error "does not match declared type" } */
+template float A<float>::a;
index ef5572f..9596bfb 100644 (file)
@@ -56,6 +56,6 @@ int main ()
 // const-ness should allow the compiler to elide references to the
 // actual variables.
 template const bool X<int>::cflag;
-template const bool X<int>::flag;
+template bool X<int>::flag;
 template const bool X<float>::cflag;
-template const bool X<float>::flag;
+template bool X<float>::flag;