This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ Patch] PR 30659

Paolo Carlini wrote:
> ... so I think a more correct fix is the below, which uses
> CP_DECL_CONTEXT. In fact, DECL_CONTEXT is documented as being NULL_TREE
> in case of global namespace. Also, I checked that the crash would not
> happen for the same broken declaration inside an user defined namespace.
> Tested x86_64-linux. Ok?

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

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

That avoids dropping into lookup_field with a NULL class type.

The change above is OK, assuming it works. :-)


Mark Mitchell
(650) 331-3385 x713

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]