From 8ea6dfaef4e67c1a505b1d7760a4fbac5f57bc36 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Mon, 12 Feb 2007 22:17:06 +0000 Subject: [PATCH] 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 From-SVN: r121864 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/pt.c | 7 +++++++ gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/template/instantiate9.C | 15 +++++++++++++++ gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C | 4 ++-- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/instantiate9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 95bcd26cac7..b7d5973536e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-02-12 Simon Martin + Mark Mitchell + + PR c++/14622 + * pt.c (do_decl_instantiation): Detect type mismatches in explicit + instantiations for variables. + 2007-02-12 Manuel Lopez-Ibanez PR middle-end/7651 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 078d433daf8..ee8db6dee25 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 a2edb27ad06..60e00e21675 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2007-02-12 Simon Martin + + 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 * 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 00000000000..20fefaf270b --- /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 A +{ + static T a; +}; + +template +T A::a; + +struct B {}; + +template B A::a; /* { dg-error "does not match declared type" } */ +template float A::a; diff --git a/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C b/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C index ef5572f9de2..9596bfbf6b3 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::cflag; -template const bool X::flag; +template bool X::flag; template const bool X::cflag; -template const bool X::flag; +template bool X::flag; -- 2.30.2