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


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

No problem :-)

> 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.

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

Cheers,
Lee.


How does the following patch look? I've included your suggestion in grokbitfield, leaving check_bitfield_decl alone to pick up any cases not detected earlier. I've also included more tests so that template instantiations like Foo<int> are accepted whilst Foo<double> isn't along with the original testcase triggered the seg-fault.

Bootstrapped and regression tested on i686-pc-linux, ok for mainline?

Cheers,
Lee.

:ADDPATCH c++:

cp/
2006-10-20  Lee Millward  <lee.millward@codesourcery.com>
           Mark Mitchell <mark@codesourcery.com>

       PR c++/28053
       * decl2.c (grokbitfield): Detect invalid non-integral
       types earlier when possible.

testsuite/
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.

Attachment: pr28053.txt
Description: Text document


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