From ff164b22d364c830b43d08e521a768b2a2957bbc Mon Sep 17 00:00:00 2001 From: Geoffrey Keating Date: Mon, 30 Aug 2004 22:19:24 +0000 Subject: [PATCH] re PR c/12738 (Missing function with 'static' block-scope declaration; unit-at-a-time; and IMA.) 2004-08-30 Geoffrey Keating PR 12738 PR 17205 Radar 3460526 Radar 3775729 * c-decl.c (grokdeclarator): Produce error for 'static' on local function declaration. Index: testsuite/ChangeLog 2004-08-30 Geoffrey Keating * gcc.dg/funcdef-storage-1.c: New. * gcc.c-torture/compile/920625-2.c: Don't use 'static' to declare an extern function in local scope. * gcc.c-torture/execute/20010605-1.c: Don't use 'static inline' to declare an 'auto inline' function in local scope. * gcc.dg/20011130-1.c: Likewise. * gcc.c-torture/execute/nest-stdar-1.c: Don't use 'static' to declare an 'auto' function in local scope. * gcc.dg/20021014-1.c: Likewise. * gcc.dg/20030331-2.c: Likewise. From-SVN: r86807 --- gcc/ChangeLog | 9 +++++ gcc/c-decl.c | 33 ++++++++++--------- gcc/testsuite/ChangeLog | 13 ++++++++ .../gcc.c-torture/compile/920625-2.c | 4 +-- .../gcc.c-torture/execute/20010605-1.c | 2 +- .../gcc.c-torture/execute/nest-stdar-1.c | 2 +- gcc/testsuite/gcc.dg/20011130-1.c | 2 +- gcc/testsuite/gcc.dg/20021014-1.c | 2 +- gcc/testsuite/gcc.dg/20030331-2.c | 2 +- gcc/testsuite/gcc.dg/funcdef-storage-1.c | 14 ++++++++ 10 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/funcdef-storage-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 00e61c6c32a..5ec3a32fc72 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2004-08-30 Geoffrey Keating + + PR 12738 + PR 17205 + Radar 3460526 + Radar 3775729 + * c-decl.c (grokdeclarator): Produce error for 'static' on local + function declaration. + 2004-08-30 Richard Henderson * expr.c (array_ref_element_size): Force aligned_size back to diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 7ef352e3541..b2f7bbe42d2 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4664,26 +4664,29 @@ grokdeclarator (tree declarator, tree declspecs, } else if (TREE_CODE (type) == FUNCTION_TYPE) { - if (specbits & (1 << (int) RID_AUTO) - && (pedantic || current_scope == file_scope)) - pedwarn ("invalid storage class for function `%s'", name); - if (specbits & (1 << (int) RID_REGISTER)) - error ("invalid storage class for function `%s'", name); - if (specbits & (1 << (int) RID_THREAD)) + if (specbits & (1 << (int) RID_REGISTER) + || specbits & (1 << (int) RID_THREAD)) error ("invalid storage class for function `%s'", name); - /* Function declaration not at file scope. - Storage classes other than `extern' are not allowed - and `extern' makes no difference. */ - if (current_scope != file_scope - && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE))) - && pedantic) - pedwarn ("invalid storage class for function `%s'", name); + else if (current_scope != file_scope) + { + /* Function declaration not at file scope. Storage + classes other than `extern' are not allowed, C99 + 6.7.1p5, and `extern' makes no difference. However, + GCC allows 'auto', perhaps with 'inline', to support + nested functions. */ + if (specbits & (1 << (int) RID_AUTO)) + { + if (pedantic) + pedwarn ("invalid storage class for function `%s'", name); + } + if (specbits & (1 << (int) RID_STATIC)) + error ("invalid storage class for function `%s'", name); + } decl = build_decl (FUNCTION_DECL, declarator, type); decl = build_decl_attribute_variant (decl, decl_attr); - DECL_LANG_SPECIFIC (decl) - = GGC_CNEW (struct lang_decl); + DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl); if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl)) pedwarn ("ISO C forbids qualified function types"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7f2e91dd374..f3dde948c83 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2004-08-30 Geoffrey Keating + + * gcc.dg/funcdef-storage-1.c: New. + * gcc.c-torture/compile/920625-2.c: Don't use 'static' to declare + an extern function in local scope. + * gcc.c-torture/execute/20010605-1.c: Don't use 'static inline' to + declare an 'auto inline' function in local scope. + * gcc.dg/20011130-1.c: Likewise. + * gcc.c-torture/execute/nest-stdar-1.c: Don't use 'static' to declare + an 'auto' function in local scope. + * gcc.dg/20021014-1.c: Likewise. + * gcc.dg/20030331-2.c: Likewise. + 2004-08-30 Tobias Schlueter * gfortran.dg/blockdata_1.f90: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/920625-2.c b/gcc/testsuite/gcc.c-torture/compile/920625-2.c index 1466285f88e..291e80d0210 100644 --- a/gcc/testsuite/gcc.c-torture/compile/920625-2.c +++ b/gcc/testsuite/gcc.c-torture/compile/920625-2.c @@ -23,7 +23,7 @@ trashQueryResult(Widget w, Boolean delete, caddr_t call_data) extern Cursor busy, left_ptr; extern String cwd; - static void freeReturnStruct(void); + extern void freeReturnStruct(void); String rmstring; int status; XedwListReturnStruct *tmp; @@ -58,7 +58,7 @@ copyQueryResult(Widget w, Boolean copy, caddr_t call_data) extern void destroy_button_dialog(); extern void changestate(Boolean); extern Cursor busy, left_ptr; - static void freeReturnStruct(void); + extern void freeReturnStruct(void); int execute(String, String, String, Boolean); extern String cwd; String copystring; diff --git a/gcc/testsuite/gcc.c-torture/execute/20010605-1.c b/gcc/testsuite/gcc.c-torture/execute/20010605-1.c index 4bf230ba54a..c777af5bdc4 100644 --- a/gcc/testsuite/gcc.c-torture/execute/20010605-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/20010605-1.c @@ -2,7 +2,7 @@ int main () { int v = 42; - static inline int fff (int x) + inline int fff (int x) { return x*10; } diff --git a/gcc/testsuite/gcc.c-torture/execute/nest-stdar-1.c b/gcc/testsuite/gcc.c-torture/execute/nest-stdar-1.c index 2c6108b52e6..492670b5a1e 100644 --- a/gcc/testsuite/gcc.c-torture/execute/nest-stdar-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/nest-stdar-1.c @@ -2,7 +2,7 @@ main () { - static double f (int x, ...) + double f (int x, ...) { va_list args; double a; diff --git a/gcc/testsuite/gcc.dg/20011130-1.c b/gcc/testsuite/gcc.dg/20011130-1.c index 393f82a91fb..60a2738fc65 100644 --- a/gcc/testsuite/gcc.dg/20011130-1.c +++ b/gcc/testsuite/gcc.dg/20011130-1.c @@ -9,7 +9,7 @@ static int __attribute__((unused)) foo (int x) { - static inline int bar (int x) + inline int bar (int x) { int y; y = x; diff --git a/gcc/testsuite/gcc.dg/20021014-1.c b/gcc/testsuite/gcc.dg/20021014-1.c index 67f88ae2f6b..dd8614c9f09 100644 --- a/gcc/testsuite/gcc.dg/20021014-1.c +++ b/gcc/testsuite/gcc.dg/20021014-1.c @@ -10,7 +10,7 @@ extern void exit (int); int foo (void) { - static int bar (int x) + int bar (int x) { return x + 3; } diff --git a/gcc/testsuite/gcc.dg/20030331-2.c b/gcc/testsuite/gcc.dg/20030331-2.c index 0509d8aad87..2fce78ea97c 100644 --- a/gcc/testsuite/gcc.dg/20030331-2.c +++ b/gcc/testsuite/gcc.dg/20030331-2.c @@ -6,7 +6,7 @@ int foo() { int yd; float in[1][yd]; - static void bar() { + void bar() { printf("%p\n",in[0]); } } diff --git a/gcc/testsuite/gcc.dg/funcdef-storage-1.c b/gcc/testsuite/gcc.dg/funcdef-storage-1.c new file mode 100644 index 00000000000..955dac28406 --- /dev/null +++ b/gcc/testsuite/gcc.dg/funcdef-storage-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ + +void +flarm(void) +{ + static void foo(); /* { dg-error "invalid storage class" } */ + + foo(); +} + +static void +foo(void) +{ +} -- 2.30.2