This is the mail archive of the gcc-patches@gcc.gnu.org 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


Lee Millward wrote:

2006-10-18 Lee Millward <lee.millward@codesourcery.com>

       PR c++/28053
       * class.c (check_bitfield_decl): Move check for bitfields
       with non integral type to...
       * decl2.c (grokbitfield): ...here.

2006-10-18 Lee Millward <lee.millward@codesourcery.com>

       PR c++/28053
       * g++.dg/parse/bitfield1.C: Adjust error markers.
       * g++.dg/parse/bitfield2.C: New test.

I hate to be a wet blanket, but I don't think this is quite right either. :-(


Consider:

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.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


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