This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH to fix [[noreturn]]


I got a note yesterday from someone trying out GCC 4.8 that noted that the compiler gave the "attribute ignored" warning for all their uses of [[noreturn]], which is one of the attributes described in the standard. Fixing this was a simple matter of mapping it onto the GNU noreturn attribute, which has the same semantics.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit 3a7e7345f4ed48d366a17cffa5addfa587d43ced
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Apr 6 21:18:01 2013 -0400

    	* parser.c (cp_parser_std_attribute): Treat [[noreturn]] like GNU
    	noreturn attribute.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index a32f1c3..ff1341a 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -20806,8 +20806,13 @@ cp_parser_std_attribute (cp_parser *parser)
       token = cp_lexer_peek_token (parser->lexer);
     }
   else
-    attribute = build_tree_list (build_tree_list (NULL_TREE, attr_id),
-				 NULL_TREE);
+    {
+      attribute = build_tree_list (build_tree_list (NULL_TREE, attr_id),
+				   NULL_TREE);
+      /* C++11 noreturn attribute is equivalent to GNU's.  */
+      if (is_attribute_p ("noreturn", attr_id))
+	TREE_PURPOSE (TREE_PURPOSE (attribute)) = get_identifier ("gnu");
+    }
 
   /* Now parse the optional argument clause of the attribute.  */
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-4.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-4.C
index bad33d6..dff46b4 100644
--- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-4.C
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-4.C
@@ -3,17 +3,17 @@
 // Test for syntax support of various attribute permutations.
 
 int
-[[gnu::noreturn]] // { dg-warning "ignored" }
+[[noreturn]] // { dg-warning "ignored" }
 one
 [[gnu::unused]]
 (void);
 
-int one_third [[gnu::noreturn]] [[gnu::unused]] (void);
+int one_third [[noreturn]] [[gnu::unused]] (void);
 
 int [[gnu::unused]] one_half(); // { dg-warning "ignored" }
 
 static
-[[gnu::noreturn]] // { dg-warning "ignored" }
+[[noreturn]] // { dg-warning "ignored" }
 void two [[gnu::unused]] (void) {}
 
 
@@ -21,10 +21,10 @@ void two [[gnu::unused]] (void) {}
 [[gnu::unused]]
 int
 five(void)
-[[gnu::noreturn]] // { dg-warning "ignored" }
+[[noreturn]] // { dg-warning "ignored" }
 {}
 
-[[gnu::noreturn]]
+[[noreturn]]
 void
 six (void)
 ;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]