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: [patch] Fix PR c++/28053

On 10/19/06, Mark Mitchell <> wrote:
I hate to be a wet blanket, but I don't think this is quite right
either. :-(

No problem :-)


template <typename T>
struct A
   T t : 3;

That's valid, because it might be that you say "A<int>" later.  (Of
course, "A<X>" for some class "X" is invalid.)  I think your patch will
issue an error about this case, because "T" is not an integral type.
So, you could adjust your patch to check:

   if (!INTEGRAL_TYPE_P (type) && !dependent_type_p (type))
     error (...);

You could get even more clever and do something like:

   if (!INTEGRAL_TYPE_P (type)
       && (POINTER_TYPE_P (type)
           || !dependent_type_p (type)))

so as to catch things like "T* t : 3", which is invalid no matter what
"T" is.  (I think anything except a TEMPLATE_TYPE_PARM or a
TYPENAME_TYPE is going to be invalid no matter what, but you might want
to think about that.)

Anyhow, if you do something like that, you'll no longer reject the valid
program above.  But, if you remove the check in check_bitfield_decl,
you'll accept invalid programs, like a subsequent use of "A<double>" in
the above program, because you won't check that "t" ends up with
integral type when instantiated.

So, the obvious thing to do is to have the checks in both places, and I
think that's perfectly reasonable.

Thanks for the advice, I'll work on a follow up patch incorporating your suggestions and resubmit.


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