Hi,
I'm still working on a number of ICEs on invalid happening during error
recovery...
In these cases, after a meaningful diagnostic, we ICE in
cxx_eval_constant_expression because it doesn't handle OVERLOADs and
TEMPLATE_ID_EXPRs in the main switch. I tried a number of different
approaches, but I think the most straightforward one is the below: avoid
setting up in grokbitfield DECL_INITIAL (and SET_DECL_C_BIT_FIELD)
after the early diagnostic, exactly as currently happens when the width
passed to the function is an error_mark_node. In particular, the
approach seems robust because the callers don't use the the width
information afterward (it's only passed to grokbitfield). Tested
x86_64-linux.
Thanks, Paolo.
///////////////////
/cp
2017-02-01 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/69637
* decl2.c (grokbitfield): In case of error don't set-up DECL_INITIAL
to the width.
/testsuite
2017-02-01 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/69637
* g++.dg/cpp0x/pr69637-1.C: New.
* g++.dg/cpp0x/pr69637-2.C: Likewise.
Index: cp/decl2.c
===================================================================
--- cp/decl2.c (revision 245084)
+++ cp/decl2.c (working copy)
@@ -1059,8 +1059,11 @@ grokbitfield (const cp_declarator *declarator,
&& !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width)))
error ("width of bit-field %qD has non-integral type %qT", value,
TREE_TYPE (width));
- DECL_INITIAL (value) = width;
- SET_DECL_C_BIT_FIELD (value);
+ else
+ {
+ DECL_INITIAL (value) = width;
+ SET_DECL_C_BIT_FIELD (value);
+ }
}
DECL_IN_AGGR_P (value) = 1;
Index: testsuite/g++.dg/cpp0x/pr69637-1.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr69637-1.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr69637-1.C (working copy)
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++11 } }
+
+template <class T>
+int foo () { return 1; }
+
+struct B {
+ unsigned c: foo; // { dg-error "non-integral type" }
+};
Index: testsuite/g++.dg/cpp0x/pr69637-2.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr69637-2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr69637-2.C (working copy)
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++11 } }
+
+template <class T, int N>
+constexpr int foo () { return N; }
+
+struct B { unsigned c: foo<int>, 3(); }; // { dg-error "non-integral
type|expected" }