Message ID | 20150320124853.GO31197@redhat.com |
---|---|
State | New |
Headers | show |
On Fri, Mar 20, 2015 at 1:48 PM, Marek Polacek <polacek@redhat.com> wrote: > The problem turned out to be that lookup_anon_field was not able to find > a FIELD_DECL so we passed NULL member to finish_class_member_access_expr > and that SEGVs on that. The reason is that "const struct C" object does > not have any fields; for that, we need to look at the main variant. So > fixed by doing just that, lookup_anon_field is then able to find the decl > and we don't ICE anymore. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? Strictly speaking, > it's not a regression, but the fix doesn't look terribly risky either. Hum... variant types should have the same TYPE_FIELDs as the main variant. So why's the variants TYPE_FIELDS NULL? Richard. > 2015-03-20 Marek Polacek <polacek@redhat.com> > > PR c++/65072 > * typeck.c (lookup_anon_field): Make sure we're dealing with the main > variant. > > * g++.dg/cpp0x/pr65072.C: New test. > > diff --git gcc/cp/typeck.c gcc/cp/typeck.c > index 4c128b7..e9d4cae 100644 > --- gcc/cp/typeck.c > +++ gcc/cp/typeck.c > @@ -2213,6 +2213,8 @@ lookup_anon_field (tree t, tree type) > { > tree field; > > + t = TYPE_MAIN_VARIANT (t); > + > for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) > { > if (TREE_STATIC (field)) > diff --git gcc/testsuite/g++.dg/cpp0x/pr65072.C gcc/testsuite/g++.dg/cpp0x/pr65072.C > index e69de29..b8fa888 100644 > --- gcc/testsuite/g++.dg/cpp0x/pr65072.C > +++ gcc/testsuite/g++.dg/cpp0x/pr65072.C > @@ -0,0 +1,14 @@ > +// PR c++/65075 > +// { dg-do compile { target c++11 } } > +// { dg-options "-Wno-pedantic" } > + > +template <typename> class C > +{ > + struct > + { > + int i; > + }; > + auto operator*(const C m) -> decltype (m.i); > +}; > +void fn1 (const C<float>); > +C<float> a; > > Marek
On Fri, Mar 20, 2015 at 01:59:14PM +0100, Richard Biener wrote: > Hum... variant types should have the same TYPE_FIELDs as the main variant. > So why's the variants TYPE_FIELDS NULL? That is a good question, but unfortunately, even after hours trying to find that out, I don't know. I thought that when we're looking for a FIELD_DECL, we should use the cv-unqualified type. Marek
On 03/20/2015 08:59 AM, Richard Biener wrote: > Hum... variant types should have the same TYPE_FIELDs as the main variant. > So why's the variants TYPE_FIELDS NULL? Because we're in the middle of parsing the class, so we haven't called fixup_type_variants to copy TYPE_FIELDS yet. The patch is OK. Jason
diff --git gcc/cp/typeck.c gcc/cp/typeck.c index 4c128b7..e9d4cae 100644 --- gcc/cp/typeck.c +++ gcc/cp/typeck.c @@ -2213,6 +2213,8 @@ lookup_anon_field (tree t, tree type) { tree field; + t = TYPE_MAIN_VARIANT (t); + for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) { if (TREE_STATIC (field)) diff --git gcc/testsuite/g++.dg/cpp0x/pr65072.C gcc/testsuite/g++.dg/cpp0x/pr65072.C index e69de29..b8fa888 100644 --- gcc/testsuite/g++.dg/cpp0x/pr65072.C +++ gcc/testsuite/g++.dg/cpp0x/pr65072.C @@ -0,0 +1,14 @@ +// PR c++/65075 +// { dg-do compile { target c++11 } } +// { dg-options "-Wno-pedantic" } + +template <typename> class C +{ + struct + { + int i; + }; + auto operator*(const C m) -> decltype (m.i); +}; +void fn1 (const C<float>); +C<float> a;