diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2857d4b35d2..8e2323bb8bb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-10-28 Paolo Carlini + Mark Mitchell + + PR c++/30659 + * pt.c (do_decl_instantiation): If the VAR_DECL is not a + class member error out and return. + 2007-10-27 Jakub Jelinek * error.c (reinit_cxx_pp): Initialize cxx_pp->enclosing_scope diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 9193f487f90..3e8f6e585da 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13882,6 +13882,11 @@ do_decl_instantiation (tree decl, tree storage) VAR_DECLs so we do the lookup here. Probably, grokdeclarator should handle VAR_DECLs as it currently handles FUNCTION_DECLs. */ + if (!DECL_CLASS_SCOPE_P (decl)) + { + error ("%qD is not a static data member of a class template", decl); + return; + } result = lookup_field (DECL_CONTEXT (decl), DECL_NAME (decl), 0, false); if (!result || TREE_CODE (result) != VAR_DECL) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 66168c796ba..cecd5f0ee19 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-10-28 Paolo Carlini + Mark Mitchell + + PR c++/30659 + * g++.dg/template/crash71.C: New. + 2007-10-28 Tobias Schlüter PR fortran/32147 diff --git a/gcc/testsuite/g++.dg/template/crash71.C b/gcc/testsuite/g++.dg/template/crash71.C new file mode 100644 index 00000000000..86aa1521d4d --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash71.C @@ -0,0 +1,3 @@ +// PR c++/30659 + +extern "C" template A foo(); // { dg-error "forbids|static data|expected" }