C++ PATCH for c++/65072 (ICE with anonymous aggregate and decltype)
Marek Polacek
polacek@redhat.com
Fri Mar 20 12:49:00 GMT 2015
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.
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
More information about the Gcc-patches
mailing list