... in fact I'm thinking that the below - which directly checks for
unqualified_id to be non-null in both places - may be a better variant:
among other things it means that for related testcases like:
typedef void a();
struct A
{ a a1: 1; };
we get the location of a1 right (we could also change the diagnostics in
grokbitfield to use DECL_SOURCE_LOCATION and exploit it), and the
testsuite doesn't need adjustments. Tested x86_64-linux.
Thanks, Paolo.
////////////////
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 266339)
+++ cp/decl.c (working copy)
@@ -12165,7 +12165,8 @@ grokdeclarator (const cp_declarator *declarator,
}
if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
- && !(identifier_p (unqualified_id)
+ && !(unqualified_id
+ && identifier_p (unqualified_id)
&& IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
{
cp_cv_quals real_quals = memfn_quals;
@@ -12245,8 +12246,7 @@ grokdeclarator (const cp_declarator *declarator,
error ("invalid use of %<::%>");
return error_mark_node;
}
- else if (TREE_CODE (type) == FUNCTION_TYPE
- || TREE_CODE (type) == METHOD_TYPE)
+ else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
{
int publicp = 0;
tree function_context;
Index: testsuite/g++.dg/parse/bitfield6.C
===================================================================
--- testsuite/g++.dg/parse/bitfield6.C (nonexistent)
+++ testsuite/g++.dg/parse/bitfield6.C (working copy)
@@ -0,0 +1,6 @@
+// PR c++/84636
+
+typedef void a();
+struct A {
+a: 1; // { dg-error "bit-field .\\<anonymous\\>. with non-integral type" }
+};