From: simartin Date: Mon, 12 Feb 2007 22:17:06 +0000 (+0000) Subject: PR c++/14622 X-Git-Tag: upstream/4.9.2~50420 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ed472d2b8df7040d56fdf7e318598da3c6201f5;p=platform%2Fupstream%2Flinaro-gcc.git PR c++/14622 * 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 --- 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 + 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 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 + + 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 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 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 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::cflag; -template const bool X::flag; +template bool X::flag; template const bool X::cflag; -template const bool X::flag; +template bool X::flag;