PR c++/91304 - prefix attributes ignored in condition.
authorMarek Polacek <polacek@redhat.com>
Fri, 23 Aug 2019 00:06:25 +0000 (00:06 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 23 Aug 2019 00:06:25 +0000 (00:06 +0000)
* parser.c (cp_parser_condition): Handle prefix attributes.

* g++.dg/cpp0x/gen-attrs-70.C: New test.

From-SVN: r274839

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/gen-attrs-70.C [new file with mode: 0644]

index d47c2f74f378802e416f0eb997444ddacf4fb2ef..d2b96231fd04e3900565ac001c59d05bf192fb76 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91304 - prefix attributes ignored in condition.
+       * parser.c (cp_parser_condition): Handle prefix attributes.
+
 2019-08-21  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR c++/91505
index dbbfe1dbc2f6a56c9f6079cf72676611c37e1b47..b410a6c030f29fda4e672c4ec70a4c83bcbd5e9a 100644 (file)
@@ -12066,6 +12066,10 @@ cp_parser_condition (cp_parser* parser)
   /* Restore the saved message.  */
   parser->type_definition_forbidden_message = saved_message;
 
+  /* Gather the attributes that were provided with the
+     decl-specifiers.  */
+  tree prefix_attributes = type_specifiers.attributes;
+
   cp_parser_maybe_commit_to_declaration (parser,
                                         type_specifiers.any_specifiers_p);
 
@@ -12116,7 +12120,7 @@ cp_parser_condition (cp_parser* parser)
          /* Create the declaration.  */
          decl = start_decl (declarator, &type_specifiers,
                             /*initialized_p=*/true,
-                            attributes, /*prefix_attributes=*/NULL_TREE,
+                            attributes, prefix_attributes,
                             &pushed_scope);
 
          /* Parse the initializer.  */
index a7c4ec33d418788d98e0d5729e2069f76d76d1e7..ad5aa69ebda315777f1ed1113e26eea2aa2a6a2b 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91304 - prefix attributes ignored in condition.
+       * g++.dg/cpp0x/gen-attrs-70.C: New test.
+
 2019-08-22  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/91490
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-70.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-70.C
new file mode 100644 (file)
index 0000000..90a2e97
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/91304 - prefix attributes ignored in condition.
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wall -Wextra" }
+
+int f();
+
+void g()
+{   
+  if ([[maybe_unused]] int i = f()) { }
+  if ([[deprecated]] int i = f()) { i = 10; } // { dg-warning ".i. is deprecated" }
+  if (int i [[maybe_unused]] = f()) { }
+  if (int i [[deprecated]] = f()) { i = 10; } // { dg-warning ".i. is deprecated" }
+}