inline trivia patch

Joseph S. Myers jsm@polyomino.org.uk
Mon Sep 13 21:28:00 GMT 2004


This patch fixes some trivial issues with the checks on the use of
"inline" that are in the nature of bug fixes and so can go in at this
stage although not proposed as a feature.

* Duplicate inline is now accepted unconditionally; on reconsidering
  past discussions I concluded there isn't really any benefit in
  retaining its rejection as a distinction between gnu89 inline and
  C99 inline.

* inline typedefs are rejected, as are inline parameters.  These are
  pedwarns since the current diagnostic for inline variables is a
  pedwarn, though perhaps all three would better be hard errors.

* inline main now gets a pedwarn rather than a warning, but isn't
  diagnosed at all in freestanding mode.

Bootstrapped with no regressions on i686-pc-linux-gnu.  Applied to
mainline.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
  http://www.srcf.ucam.org/~jsm28/gcc/#c90status - status of C90 for GCC 4.0
    jsm@polyomino.org.uk (personal mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2004-09-13  Joseph S. Myers  <jsm@polyomino.org.uk>

	* c-decl.c (grokdeclarator): Correct comments about where storage
	class specifiers are rejected by grammar and add corresponding
	asserts.  Diagnose typedefs and parameters declared inline.
	Change warning for inline main to a pedwarn.  Only diagnose inline
	main if hosted.
	(declspecs_add_scspec): Allow duplicate "inline".

testsuite:
2004-09-13  Joseph S. Myers  <jsm@polyomino.org.uk>

	* gcc.dg/declspec-7.c: Don't expect diagnostic for duplicate
	"inline".
	* gcc.dg/declspec-11.c: Update expected messages.
	* gcc.dg/inline-6.c, gcc.dg/inline-7.c, gcc.dg/inline-8.c,
	gcc.dg/inline-9.c, gcc.dg/inline-10.c, gcc.dg/inline-11.c,
	gcc.dg/inline-12.c: New tests.

diff -rupN GCC.orig/gcc/c-decl.c GCC/gcc/c-decl.c
--- GCC.orig/gcc/c-decl.c	2004-09-12 23:48:33.000000000 +0000
+++ GCC/gcc/c-decl.c	2004-09-13 11:54:33.000000000 +0000
@@ -4356,8 +4356,6 @@ grokdeclarator (const struct c_declarato
   if (storage_class == csc_typedef)
     {
       tree decl;
-      /* Note that the grammar rejects storage classes
-	 in typenames, fields or parameters */
       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
 	  && type_quals)
 	pedwarn ("ISO C forbids qualified function types");
@@ -4368,6 +4366,8 @@ grokdeclarator (const struct c_declarato
 	  || declspecs->typedef_signed_p)
 	C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
       decl_attributes (&decl, returned_attrs, 0);
+      if (declspecs->inline_p)
+	pedwarn ("%Jtypedef %qD declared %<inline%>", decl, decl);
       return decl;
     }
 
@@ -4391,8 +4391,10 @@ grokdeclarator (const struct c_declarato
 
   if (decl_context == TYPENAME)
     {
-      /* Note that the grammar rejects storage classes
-	 in typenames, fields or parameters */
+      /* Note that the grammar rejects storage classes in typenames
+	 and fields.  */
+      gcc_assert (storage_class == csc_none && !threadp
+		  && !declspecs->inline_p);
       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
 	  && type_quals)
 	pedwarn ("ISO C forbids const or volatile function types");
@@ -4495,9 +4497,16 @@ grokdeclarator (const struct c_declarato
 
 	DECL_ARG_TYPE (decl) = promoted_type;
 	DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
+	if (declspecs->inline_p)
+	  pedwarn ("%Jparameter %qD declared %<inline%>", decl, decl);
       }
     else if (decl_context == FIELD)
       {
+	/* Note that the grammar rejects storage classes in typenames
+	   and fields.  */
+	gcc_assert (storage_class == csc_none && !threadp
+		    && !declspecs->inline_p);
+
 	/* Structure field.  It may not be a function.  */
 
 	if (TREE_CODE (type) == FUNCTION_TYPE)
@@ -4579,10 +4588,10 @@ grokdeclarator (const struct c_declarato
 	  C_FUNCTION_IMPLICIT_INT (decl) = 1;
 
 	/* Record presence of `inline', if it is reasonable.  */
-	if (MAIN_NAME_P (declarator->u.id))
+	if (flag_hosted && MAIN_NAME_P (declarator->u.id))
 	  {
 	    if (declspecs->inline_p)
-	      warning ("cannot inline function %<main%>");
+	      pedwarn ("cannot inline function %<main%>");
 	  }
 	else if (declspecs->inline_p)
 	  {
@@ -6858,10 +6867,11 @@ declspecs_add_scspec (struct c_declspecs
   switch (i)
     {
     case RID_INLINE:
-      /* GCC has hitherto given an error for duplicate inline, but
-	 this should be revisited since C99 permits duplicate
-	 inline.  */
-      dupe = specs->inline_p;
+      /* C99 permits duplicate inline.  Although of doubtful utility,
+	 it seems simplest to permit it in gnu89 mode as well, as
+	 there is also little utility in maintaining this as a
+	 difference between gnu89 and C99 inline.  */
+      dupe = false;
       specs->inline_p = true;
       break;
     case RID_THREAD:
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/declspec-11.c GCC/gcc/testsuite/gcc.dg/declspec-11.c
--- GCC.orig/gcc/testsuite/gcc.dg/declspec-11.c	2004-09-12 23:48:33.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/declspec-11.c	2004-09-13 19:36:10.000000000 +0000
@@ -42,4 +42,4 @@ register void f8 (void); /* { dg-error "
 void i (void) { auto void y (void) {} } /* { dg-error "error: ISO C forbids nested functions" } */
 /* { dg-error "error: function definition declared 'auto'" "nested" { target *-*-* } 42 } */
 
-inline int main (void) { return 0; } /* { dg-warning "warning: cannot inline function 'main'" } */
+inline int main (void) { return 0; } /* { dg-error "error: cannot inline function 'main'" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/declspec-7.c GCC/gcc/testsuite/gcc.dg/declspec-7.c
--- GCC.orig/gcc/testsuite/gcc.dg/declspec-7.c	2004-09-11 21:23:10.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/declspec-7.c	2004-09-13 11:44:22.000000000 +0000
@@ -8,7 +8,7 @@
 
 /* Duplicate specifiers.  */
 
-inline inline void f0 (void), /* { dg-error "error: duplicate 'inline'" } */
+inline inline void f0 (void),
   f1 (void);
 
 static static int a, /* { dg-error "error: duplicate 'static'" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/inline-10.c GCC/gcc/testsuite/gcc.dg/inline-10.c
--- GCC.orig/gcc/testsuite/gcc.dg/inline-10.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/inline-10.c	2004-09-13 12:00:16.000000000 +0000
@@ -0,0 +1,6 @@
+/* Test inline main, gnu99 mode, freestanding, -pedantic-errors.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -ffreestanding -pedantic-errors" } */
+
+inline int main (void);
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/inline-11.c GCC/gcc/testsuite/gcc.dg/inline-11.c
--- GCC.orig/gcc/testsuite/gcc.dg/inline-11.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/inline-11.c	2004-09-13 19:37:11.000000000 +0000
@@ -0,0 +1,14 @@
+/* Test misuses of inline.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+/* These should perhaps be hard errors, but are pedwarns at
+   present.  */
+
+inline int a; /* { dg-warning "warning: variable 'a' declared 'inline'" } */
+inline int (*b)(void); /* { dg-warning "warning: variable 'b' declared 'inline'" } */
+typedef inline void c(void); /* { dg-warning "warning: typedef 'c' declared 'inline'" } */
+typedef inline int d; /* { dg-warning "warning: typedef 'd' declared 'inline'" } */
+void e(inline int f(void)); /* { dg-warning "warning: parameter 'f' declared 'inline'" } */
+void g(inline int(void)); /* { dg-warning "warning: parameter '\\({anonymous}\\)' declared 'inline'" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/inline-12.c GCC/gcc/testsuite/gcc.dg/inline-12.c
--- GCC.orig/gcc/testsuite/gcc.dg/inline-12.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/inline-12.c	2004-09-13 19:37:19.000000000 +0000
@@ -0,0 +1,14 @@
+/* Test misuses of inline.  -pedantic-errors test.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+
+/* These should perhaps be hard errors, but are pedwarns at
+   present.  */
+
+inline int a; /* { dg-error "error: variable 'a' declared 'inline'" } */
+inline int (*b)(void); /* { dg-error "error: variable 'b' declared 'inline'" } */
+typedef inline void c(void); /* { dg-error "error: typedef 'c' declared 'inline'" } */
+typedef inline int d; /* { dg-error "error: typedef 'd' declared 'inline'" } */
+void e(inline int f(void)); /* { dg-error "error: parameter 'f' declared 'inline'" } */
+void g(inline int(void)); /* { dg-error "error: parameter '\\({anonymous}\\)' declared 'inline'" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/inline-6.c GCC/gcc/testsuite/gcc.dg/inline-6.c
--- GCC.orig/gcc/testsuite/gcc.dg/inline-6.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/inline-6.c	2004-09-13 11:58:10.000000000 +0000
@@ -0,0 +1,6 @@
+/* Test duplicate inline, gnu89 mode.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89" } */
+
+inline inline void f (void) {}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/inline-7.c GCC/gcc/testsuite/gcc.dg/inline-7.c
--- GCC.orig/gcc/testsuite/gcc.dg/inline-7.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/inline-7.c	2004-09-13 11:58:19.000000000 +0000
@@ -0,0 +1,6 @@
+/* Test duplicate inline, gnu99 mode.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+inline inline void f (void) {}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/inline-8.c GCC/gcc/testsuite/gcc.dg/inline-8.c
--- GCC.orig/gcc/testsuite/gcc.dg/inline-8.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/inline-8.c	2004-09-13 11:59:35.000000000 +0000
@@ -0,0 +1,6 @@
+/* Test inline main, gnu99 mode, hosted.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fhosted" } */
+
+inline int main (void); /* { dg-warning "warning: cannot inline function 'main'" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/inline-9.c GCC/gcc/testsuite/gcc.dg/inline-9.c
--- GCC.orig/gcc/testsuite/gcc.dg/inline-9.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/inline-9.c	2004-09-13 11:59:57.000000000 +0000
@@ -0,0 +1,6 @@
+/* Test inline main, gnu99 mode, hosted, -pedantic-errors.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fhosted -pedantic-errors" } */
+
+inline int main (void); /* { dg-error "error: cannot inline function 'main'" } */



More information about the Gcc-patches mailing list