aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Martin <simartin@users.sourceforge.net>2007-02-12 22:17:06 +0000
committerSimon Martin <simartin@gcc.gnu.org>2007-02-12 22:17:06 +0000
commit8ea6dfaef4e67c1a505b1d7760a4fbac5f57bc36 (patch)
tree6eec4be017606e31d96f1ea0e5048763ddd6d267
parent0f7b6776a325fafa3244019a7b995ec9045573d0 (diff)
downloadgcc-8ea6dfaef4e67c1a505b1d7760a4fbac5f57bc36.zip
gcc-8ea6dfaef4e67c1a505b1d7760a4fbac5f57bc36.tar.gz
gcc-8ea6dfaef4e67c1a505b1d7760a4fbac5f57bc36.tar.bz2
re PR c++/14622 (type mismatch in explicit template instantiation not detected)
PR c++/14622 * pt.c (do_decl_instantiation): Detect type mismatches in explicit instantiations for variables. Co-Authored-By: Mark Mitchell <mark@codesourcery.com> From-SVN: r121864
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/pt.c7
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/template/instantiate9.C15
-rw-r--r--gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C4
5 files changed, 38 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 95bcd26..b7d5973 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 078d433..ee8db6d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a2edb27..60e00e2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..20fefaf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/instantiate9.C
@@ -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;
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C b/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C
index ef5572f..9596bfb 100644
--- a/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C
+++ b/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C
@@ -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;