]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/60915 (confusing diagnostic from attribute on function definition)
authorMarek Polacek <polacek@redhat.com>
Thu, 1 May 2014 07:40:26 +0000 (07:40 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 1 May 2014 07:40:26 +0000 (07:40 +0000)
PR c/60915
* c-parser.c (c_parser_declaration_or_fndef): Give better error if
function-definition has an attribute after the declarator.

* gcc.dg/pr60915.c: New test.

From-SVN: r209975

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr60915.c [new file with mode: 0644]

index 8cc268b0f7b7c20dda87b324e4fc366b5e9ff27a..a5b4f5f17a5e45aaef014c6c5a9b3c8787b0ae80 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60915
+       * c-parser.c (c_parser_declaration_or_fndef): Give better error if
+       function-definition has an attribute after the declarator.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/60257
index 56f79f6a795b61af07f49743dfead069f5a759a5..c22c4abcb263a0e605166a4a8e1adfeef912d090 100644 (file)
@@ -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;
index 6424b854a4f16352058d83aafd43f22642e17559..f5976b9ace0b755d0ead801c089cba93383c33c9 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60915
+       * gcc.dg/pr60915.c: New test.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/60257
diff --git a/gcc/testsuite/gcc.dg/pr60915.c b/gcc/testsuite/gcc.dg/pr60915.c
new file mode 100644 (file)
index 0000000..2ed0a5f
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR c/60915 */
+/* { dg-do compile } */
+
+void /* { dg-error "attributes should be specified before the declarator in a function definition" } */
+foo (void) __attribute__((__visibility__("default")))
+{
+}