diff options
| author | simartin <simartin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-12 22:17:06 +0000 |
|---|---|---|
| committer | simartin <simartin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-12 22:17:06 +0000 |
| commit | 8ed472d2b8df7040d56fdf7e318598da3c6201f5 (patch) | |
| tree | 6eec4be017606e31d96f1ea0e5048763ddd6d267 | |
| parent | ec29ad3ea2f37a500974ad0740bfe4274878c3de (diff) | |
| download | ppe42-gcc-8ed472d2b8df7040d56fdf7e318598da3c6201f5.tar.gz ppe42-gcc-8ed472d2b8df7040d56fdf7e318598da3c6201f5.zip | |
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
| -rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
| -rw-r--r-- | gcc/cp/pt.c | 7 | ||||
| -rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
| -rw-r--r-- | gcc/testsuite/g++.dg/template/instantiate9.C | 15 | ||||
| -rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C | 4 |
5 files changed, 38 insertions, 2 deletions
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 <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 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 <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 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 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 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<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; |

