From: Joseph Myers Date: Mon, 13 Sep 2004 21:00:33 +0000 (+0100) Subject: c-decl.c (grokdeclarator): Correct comments about where storage class specifiers... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=61f4f1cc3d363590bec97bc8fb035064d617bd73;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 31e7739384f..3166bd15c66 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2004-09-13 Joseph S. Myers + + * 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 * config/ia64/ia64.c (ia64_scalar_mode_supported_p): New. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 7d986cdf24d..1d6c40dd0b0 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -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 %", 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 %", 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 %"); + pedwarn ("cannot inline function %"); } 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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e4bea8c9b81..4353e177c08 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2004-09-13 Joseph S. Myers + + * 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 * g++.dg/tree-ssa/pr17400.C: New testcase. diff --git a/gcc/testsuite/gcc.dg/declspec-11.c b/gcc/testsuite/gcc.dg/declspec-11.c index 2f4eaff3b25..6c6892fe11f 100644 --- a/gcc/testsuite/gcc.dg/declspec-11.c +++ b/gcc/testsuite/gcc.dg/declspec-11.c @@ -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'" } */ diff --git a/gcc/testsuite/gcc.dg/declspec-7.c b/gcc/testsuite/gcc.dg/declspec-7.c index bb63d952d88..1cd4e836d62 100644 --- a/gcc/testsuite/gcc.dg/declspec-7.c +++ b/gcc/testsuite/gcc.dg/declspec-7.c @@ -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 --git a/gcc/testsuite/gcc.dg/inline-10.c b/gcc/testsuite/gcc.dg/inline-10.c new file mode 100644 index 00000000000..ed6851a615b --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline-10.c @@ -0,0 +1,6 @@ +/* Test inline main, gnu99 mode, freestanding, -pedantic-errors. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -ffreestanding -pedantic-errors" } */ + +inline int main (void); diff --git a/gcc/testsuite/gcc.dg/inline-11.c b/gcc/testsuite/gcc.dg/inline-11.c new file mode 100644 index 00000000000..6d0f41d969c --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline-11.c @@ -0,0 +1,14 @@ +/* Test misuses of inline. */ +/* Origin: Joseph Myers */ +/* { 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 --git a/gcc/testsuite/gcc.dg/inline-12.c b/gcc/testsuite/gcc.dg/inline-12.c new file mode 100644 index 00000000000..c793196fe72 --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline-12.c @@ -0,0 +1,14 @@ +/* Test misuses of inline. -pedantic-errors test. */ +/* Origin: Joseph Myers */ +/* { 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 --git a/gcc/testsuite/gcc.dg/inline-6.c b/gcc/testsuite/gcc.dg/inline-6.c new file mode 100644 index 00000000000..81d6dc22082 --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline-6.c @@ -0,0 +1,6 @@ +/* Test duplicate inline, gnu89 mode. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89" } */ + +inline inline void f (void) {} diff --git a/gcc/testsuite/gcc.dg/inline-7.c b/gcc/testsuite/gcc.dg/inline-7.c new file mode 100644 index 00000000000..b239a20461c --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline-7.c @@ -0,0 +1,6 @@ +/* Test duplicate inline, gnu99 mode. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +inline inline void f (void) {} diff --git a/gcc/testsuite/gcc.dg/inline-8.c b/gcc/testsuite/gcc.dg/inline-8.c new file mode 100644 index 00000000000..80d9fff5440 --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline-8.c @@ -0,0 +1,6 @@ +/* Test inline main, gnu99 mode, hosted. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -fhosted" } */ + +inline int main (void); /* { dg-warning "warning: cannot inline function 'main'" } */ diff --git a/gcc/testsuite/gcc.dg/inline-9.c b/gcc/testsuite/gcc.dg/inline-9.c new file mode 100644 index 00000000000..0f22b0805a3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline-9.c @@ -0,0 +1,6 @@ +/* Test inline main, gnu99 mode, hosted, -pedantic-errors. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -fhosted -pedantic-errors" } */ + +inline int main (void); /* { dg-error "error: cannot inline function 'main'" } */