From e0c9fbb7638b1d558eab84e981b2347fbf97c59a Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 25 Oct 2000 18:45:44 +0100 Subject: c-decl.c (grokdeclarator): Move warning for qualified void return types with -pedantic to when... * c-decl.c (grokdeclarator): Move warning for qualified void return types with -pedantic to when the function type is constructed. At -W, warn in general for qualified function return types, except for volatile void. * invoke.texi: Document this new warning at -W. testsuite: * gcc.dg/qual-return-1.c, gcc.dg/qual-return-2.c: New tests. From-SVN: r37056 --- gcc/ChangeLog | 8 ++++++++ gcc/c-decl.c | 27 ++++++++++++++++++++------- gcc/invoke.texi | 7 +++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/qual-return-1.c | 24 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/qual-return-2.c | 14 ++++++++++++++ 6 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/qual-return-1.c create mode 100644 gcc/testsuite/gcc.dg/qual-return-2.c (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c605f67..1e708d9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2000-10-25 Joseph S. Myers + + * c-decl.c (grokdeclarator): Move warning for qualified void + return types with -pedantic to when the function type is + constructed. At -W, warn in general for qualified function return + types, except for volatile void. + * invoke.texi: Document this new warning at -W. + 2000-10-25 Neil Booth * cpp.texi: Update with implementation-defined behavior and diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 00e7b91..51d76c5 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4577,7 +4577,26 @@ grokdeclarator (declarator, declspecs, decl_context, initialized) /* Type qualifiers before the return type of the function qualify the return type, not the function type. */ if (type_quals) - type = c_build_qualified_type (type, type_quals); + { + /* Type qualifiers on a function return type are normally + permitted by the standard but have no effect, so give a + warning at -W. Qualifiers on a void return type have + meaning as a GNU extension, and are banned on function + definitions in ISO C. FIXME: strictly we shouldn't + pedwarn for qualified void return types except on function + definitions, but not doing so could lead to the undesirable + state of a "volatile void" function return type not being + warned about, and a use of the function being compiled + with GNU semantics, with no diagnostics under -pedantic. */ + if (VOID_TYPE_P (type) && pedantic && !in_system_header) + pedwarn ("ISO C forbids qualified void function return type"); + else if (extra_warnings + && !(VOID_TYPE_P (type) + && type_quals == TYPE_QUAL_VOLATILE)) + warning ("type qualifiers ignored on function return type"); + + type = c_build_qualified_type (type, type_quals); + } type_quals = TYPE_UNQUALIFIED; type = build_function_type (type, arg_types); @@ -4854,12 +4873,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized) if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl)) pedwarn ("ISO C forbids qualified function types"); - if (pedantic - && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))) - && TYPE_QUALS (TREE_TYPE (TREE_TYPE (decl))) - && ! DECL_IN_SYSTEM_HEADER (decl)) - pedwarn ("ISO C forbids qualified void function return type"); - /* GNU C interprets a `volatile void' return type to indicate that the function does not return. */ if ((type_quals & TYPE_QUAL_VOLATILE) diff --git a/gcc/invoke.texi b/gcc/invoke.texi index 73dd1d9..bc05406 100644 --- a/gcc/invoke.texi +++ b/gcc/invoke.texi @@ -1817,6 +1817,13 @@ Storage-class specifiers like @code{static} are not the first things in a declaration. According to the C Standard, this usage is obsolescent. @item +The return type of a function has a type qualifier such as @code{const}. +Such a type qualifier has no effect, since the value returned by a +function is not an lvalue. (But don't warn about the GNU extension of +@code{volatile void} return types. That extension will be warned about +if @samp{-pedantic} is specified.) + +@item If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused arguments. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f61fb4e..3c75d3c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2000-10-25 Joseph S. Myers + + * gcc.dg/qual-return-1.c, gcc.dg/qual-return-2.c: New tests. + 2000-10-25 Jakub Jelinek * gcc.c-torture/execute/20001024-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/qual-return-1.c b/gcc/testsuite/gcc.dg/qual-return-1.c new file mode 100644 index 0000000..5cab75c --- /dev/null +++ b/gcc/testsuite/gcc.dg/qual-return-1.c @@ -0,0 +1,24 @@ +/* Test for warnings for qualified function return types. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -W" } */ + +/* Qualifying a function return type makes no sense. */ + +const int int_fn (void); /* { dg-warning "qualifiers" "int decl" } */ +const int (*int_ptr) (void); /* { dg-warning "qualifiers" "int ptr" } */ +const int int_fn2 (void) { return 0; } /* { dg-warning "qualifiers" "int defn" } */ + +const void void_fn (void); /* { dg-warning "qualifiers" "void decl" } */ +const void (*void_ptr) (void); /* { dg-warning "qualifiers" "void ptr" } */ +const void void_fn2 (void) { } /* { dg-warning "qualifiers" "void defn" } */ + +/* "volatile void" is a GNU extension, so only warn at -pedantic. */ + +volatile void vvoid_fn (void); +volatile void (*vvoid_ptr) (void); +volatile void vvoid_fn2 (void) { } + +int *restrict ip_fn (void); /* { dg-warning "qualifiers" "restrict decl" } */ +int *restrict (*ip_ptr) (void); /* { dg-warning "qualifiers" "restrict ptr" } */ +int *restrict ip_fn2 (void) { return (int *)0; }; /* { dg-warning "qualifiers" "restrict defn" } */ diff --git a/gcc/testsuite/gcc.dg/qual-return-2.c b/gcc/testsuite/gcc.dg/qual-return-2.c new file mode 100644 index 0000000..272787e --- /dev/null +++ b/gcc/testsuite/gcc.dg/qual-return-2.c @@ -0,0 +1,14 @@ +/* Test for warnings for qualified function return types. -pedantic test. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-pedantic" } */ + +/* Qualifying a function return type makes no sense. */ + +/* "volatile void" is a GNU extension, so only warn at -pedantic. + Strictly, the first two of these should warn only if the function is + somewhere used or defined. */ + +volatile void vvoid_fn (void); /* { dg-warning "qualified" "volatile decl" } */ +volatile void (*vvoid_ptr) (void); /* { dg-warning "qualified" "volatile ptr" } */ +volatile void vvoid_fn2 (void) { } /* { dg-warning "qualified" "volatile defn" } */ -- cgit v1.1