http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31489
Paolo Carlini <paolo.carlini at oracle dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot |gnu.org |com --- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-27 10:06:09 UTC --- I just discovered that actually we *do* have machinery to do this, in general terms (see CLASSTYPE_DECLARED_CLASS, used by eg, class_key_or_enum_as_string). But cp_parser_elaborated_type_specifier doesn't use it, ie doesn't set CLASSTYPE_DECLARED_CLASS (at variance with cp_parser_class_head). Thus something like the following patchlet should do the trick. That said, Andrew has a point of course, for its second example we would say struct or class, whichever comes last in the redeclaration. All in all, seems an improvement to me, if the below works pretty well I'm going to submit it. ///////////// Index: parser.c =================================================================== --- parser.c (revision 179242) +++ parser.c (working copy) @@ -13423,8 +13423,15 @@ 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. */ cp_parser_check_for_invalid_template_id (parser, type, token->location);