+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".
+
2004-09-13 Steve Ellcey <sje@cup.hp.com>
* config/ia64/ia64.c (ia64_scalar_mode_supported_p): New.
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");
|| 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;
}
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");
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)
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)
{
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:
+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.
+
2004-09-13 Andrew MacLeod <amacleod@redhat.com>
* g++.dg/tree-ssa/pr17400.C: New testcase.
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'" } */
/* 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'" } */
--- /dev/null
+/* 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);
--- /dev/null
+/* 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'" } */
--- /dev/null
+/* 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'" } */
--- /dev/null
+/* Test duplicate inline, gnu89 mode. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89" } */
+
+inline inline void f (void) {}
--- /dev/null
+/* Test duplicate inline, gnu99 mode. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+inline inline void f (void) {}
--- /dev/null
+/* 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'" } */
--- /dev/null
+/* 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'" } */