http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60915

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Tom Tromey from comment #0)
> First, while this is not the correct syntax, it seems natural
> enough that I've written it several times by mistake now.
> Is there any chance it could be blessed?

It looks like it.  Quoting from
http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax: "An
attribute specifier list may, in future, be permitted to appear after the
declarator in a function definition (before any old-style parameter
declarations or the function body)."

> Second, I think the diagnostic could be improved.  For example
> it could mention that an attribute is not valid in this position
> on a definition, and suggest an alternative.

Yep.  The following (untested) patch should bring hopefully better error
message; do you agree with the wording?

--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1688,7 +1688,19 @@ c_parser_declaration_or_fndef (c_parser *parser, bool
fndef_ok,
          if (c_parser_next_token_is_keyword (parser, RID_ASM))
            asm_name = c_parser_simple_asm_expr (parser);
          if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
-           postfix_attrs = c_parser_attributes (parser);
+           {
+             postfix_attrs = c_parser_attributes (parser);
+             if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
+               {
+                 /* This means there is an attribute specifier after
+                    the declarator in a function definition.  Provide
+                    some more information for the user.  */
+                 error_at (here, "attributes should be specified before the "
+                           "declarator in a function definition");
+                 c_parser_skip_to_end_of_block_or_statement (parser);
+                 return;
+               }
+           }
          if (c_parser_next_token_is (parser, CPP_EQ))
            {
              tree d;

This would of course go away if we decide to support attribute specifier after
the declarator in a function definition.

> Third, the manual could use an example of how to do this.

Yeah, an example never hurts.

Reply via email to