Commit 61f4f1cc by Joseph Myers Committed by Joseph Myers

c-decl.c (grokdeclarator): Correct comments about where storage class specifiers…

c-decl.c (grokdeclarator): Correct comments about where storage class specifiers are rejected by grammar...

	* 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:
	* 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.

From-SVN: r87450
parent b4cb0e43
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.
......
......@@ -4356,8 +4356,6 @@ grokdeclarator (const struct c_declarator *declarator,
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_declarator *declarator,
|| 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_declarator *declarator,
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_declarator *declarator,
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_declarator *declarator,
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 *specs, tree scspec)
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.
......
......@@ -42,4 +42,4 @@ register void f8 (void); /* { dg-error "error: invalid storage class for functio
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'" } */
......@@ -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'" } */
......
/* 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);
/* 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'" } */
/* 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'" } */
/* Test duplicate inline, gnu89 mode. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
/* { dg-options "-std=gnu89" } */
inline inline void f (void) {}
/* Test duplicate inline, gnu99 mode. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
/* { dg-options "-std=gnu99" } */
inline inline void f (void) {}
/* 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'" } */
/* 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'" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment