This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ Patch] PR 30659
Hi Mark,
> I think you've found the offender, but I think there's a better fix. In
> particular, in do_decl_instantiation (which should really be called
> something like perform_explicit_instantiation), we allow the VAR_DECL
> case for exactly one reason: to support explicit instantiation of static
> data members:
>
> template <typename T> struct S { static int i; };
> template <typename T> int S<T>::i;
> template int S<double>::i; // Instantiation
>
Thanks for the explanation.
> If the VAR_DECL is not a class member, then we can issue a good error
> message in do_decl_instantiation:
>
> if (!DECL_CLASS_SCOPE_P (decl))
> {
> error ("%qD is not a static data member of a class template", decl);
> return;
> }
>
> That avoids dropping into lookup_field with a NULL class type.
>
Indeed, I was slightly nervous because of the pointless lookup_field
call but was missing too many details to figure out the
DECL_CLASS_SCOPE_P check myself...
> The change above is OK, assuming it works. :-)
>
Indeed it does. I'm committing the below.
Thanks!
Paolo.
/////////////////////
cp/
2007-10-28 Paolo Carlini <pcarlini@suse.de>
Mark Mitchell <mark@codesourcery.com>
PR c++/30659
* pt.c (do_decl_instantiation): If the VAR_DECL is not a
class member error out and return.
testsuite/
2007-10-28 Paolo Carlini <pcarlini@suse.de>
Mark Mitchell <mark@codesourcery.com>
PR c++/30659
* g++.dg/template/crash71.C: New.
Index: testsuite/g++.dg/template/crash71.C
===================================================================
*** testsuite/g++.dg/template/crash71.C (revision 0)
--- testsuite/g++.dg/template/crash71.C (revision 0)
***************
*** 0 ****
--- 1,3 ----
+ // PR c++/30659
+
+ extern "C" template A<char> foo(); // { dg-error "forbids|static data|expected" }
Index: cp/pt.c
===================================================================
*** cp/pt.c (revision 129697)
--- cp/pt.c (working copy)
*************** do_decl_instantiation (tree decl, tree s
*** 13882,13887 ****
--- 13882,13892 ----
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)
{