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
This commit is contained in:
Simon Martin 2007-02-12 22:17:06 +00:00 committed by Simon Martin
parent 0f7b6776a3
commit 8ea6dfaef4
5 changed files with 38 additions and 2 deletions

View 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

View 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)
{

View 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.

View File

@ -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;

View 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;