diff mbox

C1X _Noreturn

Message ID Pine.LNX.4.64.1108191326140.6986@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers Aug. 19, 2011, 1:26 p.m. UTC
On Thu, 18 Aug 2011, Gabriel Dos Reis wrote:

> On Thu, Aug 18, 2011 at 4:37 PM, Joseph S. Myers
> <joseph@codesourcery.com> wrote:
> 
> > The new keyword is C-only (C++0x has a different way of declaring
> > non-returning functions) and I did not try to make the header do
> > anything useful if included in C++ code.
> 
> I would suggest you don't define it all as macro when __cplusplus is defined.

This followup patch:

* stops stdnoreturn.h from defining the noreturn macro for C++, as
  suggested;

* adds a pedwarn-if-pedantic for using _Noreturn outside C1X mode (not
  formally required as it's in the reserved namespace, but still seems
  useful and is similar to what's done with _Complex, for example);

* mentions _Noreturn in the syntax comments in the C parser.

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Applied
to mainline.

2011-08-19  Joseph Myers  <joseph@codesourcery.com>

	* c-decl.c (grokdeclarator): Diagnose _Noreturn for non-C1X if
	pedantic.
	* c-parser.c (c_parser_declspecs): Include _Noreturn in syntax
	comment.
	* ginclude/stdnoreturn.h (noreturn): Don't define for C++.

testsuite:
2011-08-19  Joseph Myers  <joseph@codesourcery.com>

	* gcc.dg/c90-noreturn-1.c, gcc.dg/c99-noreturn-1.c: New tests.
diff mbox

Patch

Index: gcc/ginclude/stdnoreturn.h
===================================================================
--- gcc/ginclude/stdnoreturn.h	(revision 177894)
+++ gcc/ginclude/stdnoreturn.h	(working copy)
@@ -26,6 +26,10 @@  see the files COPYING3 and COPYING.RUNTI
 #ifndef _STDNORETURN_H
 #define _STDNORETURN_H
 
+#ifndef __cplusplus
+
 #define noreturn _Noreturn
 
+#endif
+
 #endif	/* stdnoreturn.h */
Index: gcc/testsuite/gcc.dg/c99-noreturn-1.c
===================================================================
--- gcc/testsuite/gcc.dg/c99-noreturn-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/c99-noreturn-1.c	(revision 0)
@@ -0,0 +1,5 @@ 
+/* Test _Noreturn not in C99.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+_Noreturn void f (void); /* { dg-error "ISO C99 does not support '_Noreturn'" } */
Index: gcc/testsuite/gcc.dg/c90-noreturn-1.c
===================================================================
--- gcc/testsuite/gcc.dg/c90-noreturn-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/c90-noreturn-1.c	(revision 0)
@@ -0,0 +1,5 @@ 
+/* Test _Noreturn not in C90.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
+
+_Noreturn void f (void); /* { dg-error "ISO C90 does not support '_Noreturn'" } */
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 177894)
+++ gcc/c-decl.c	(working copy)
@@ -5986,7 +5986,18 @@  grokdeclarator (const struct c_declarato
 	      /* Record that the function is declared `inline'.  */
 	      DECL_DECLARED_INLINE_P (decl) = 1;
 	    if (declspecs->noreturn_p)
-	      TREE_THIS_VOLATILE (decl) = 1;
+	      {
+		if (!flag_isoc1x)
+		  {
+		    if (flag_isoc99)
+		      pedwarn (loc, OPT_pedantic,
+			       "ISO C99 does not support %<_Noreturn%>");
+		    else
+		      pedwarn (loc, OPT_pedantic,
+			       "ISO C90 does not support %<_Noreturn%>");
+		  }
+		TREE_THIS_VOLATILE (decl) = 1;
+	      }
 	  }
       }
     else
Index: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c	(revision 177894)
+++ gcc/c-parser.c	(working copy)
@@ -1905,6 +1905,9 @@  c_parser_static_assert_declaration_no_se
    C99 6.7.4:
    function-specifier:
      inline
+     _Noreturn
+
+   (_Noreturn is new in C1X.)
 
    C90 6.5.2, C99 6.7.2:
    type-specifier: