Hi,
submitter asks us to be more accurate in some error messages about
naming 'struct' vs 'class'.
Turns out - IMHO the issue is a bit nitpicking - that we do have in
place machinery for this, already used by cp_parser_class_head, which
sets CLASSTYPE_DECLARED_CLASS appropriately. I'm simply doing the same
in cp_parser_elaborated_type_specifier too, thus set the latter just
before calling cp_parser_check_class_key.
Tested x86_64-linux. Ok for mainline?
Thanks,
Paolo.
////////////////////
/cp
2011-09-27 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/31489
* parser.c (cp_parser_elaborated_type_specifier): For RECORD_TYPE,
set CLASSTYPE_DECLARED_CLASS.
/testsuite
2011-09-27 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/31489
* g++.dg/parse/error40.C: New.
* g++.dg/warn/incomplete1.C: Adjust.
Index: testsuite/g++.dg/warn/incomplete1.C
===================================================================
--- testsuite/g++.dg/warn/incomplete1.C (revision 179242)
+++ testsuite/g++.dg/warn/incomplete1.C (working copy)
@@ -9,7 +9,7 @@
// (But the deletion does not constitute an ill-formed program. So the
// program should nevertheless compile, but it should give a warning.)
-class A; // { dg-warning "forward declaration of 'struct A'" "" }
+class A; // { dg-warning "forward declaration of 'class A'" "" }
A *a; // { dg-warning "'a' has incomplete type" "" }
Index: testsuite/g++.dg/parse/error40.C
===================================================================
--- testsuite/g++.dg/parse/error40.C (revision 0)
+++ testsuite/g++.dg/parse/error40.C (revision 0)
@@ -0,0 +1,8 @@
+// PR c++/31489
+
+class foobar; // { dg-error "'class foobar'" }
+
+int main()
+{
+ foobar * o = new foobar; // { dg-error "'class foobar'" }
+}
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 179242)
+++ cp/parser.c (working copy)
@@ -13423,7 +13423,13 @@ cp_parser_elaborated_type_specifier (cp_parser* pa
}
if (tag_type != enum_type)
- cp_parser_check_class_key (tag_type, type);
+ {
+ /* Indicate whether this class was declared as a `class' or as a
+ `struct'. */
+ if (TREE_CODE (type) == RECORD_TYPE)
+ CLASSTYPE_DECLARED_CLASS (type) = (tag_type == class_type);
+ cp_parser_check_class_key (tag_type, type);
+ }
/* A "<" cannot follow an elaborated type specifier. If that
happens, the user was probably trying to form a template-id. */