aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2000-10-25 18:45:44 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2000-10-25 18:45:44 +0100
commite0c9fbb7638b1d558eab84e981b2347fbf97c59a (patch)
treee053df2a3f9528985c3178bcc90e1d30062e9d4e /gcc/c-decl.c
parentfb204271dd889c63b0427b4ab48dd04b3ded329c (diff)
downloadgcc-e0c9fbb7638b1d558eab84e981b2347fbf97c59a.zip
gcc-e0c9fbb7638b1d558eab84e981b2347fbf97c59a.tar.gz
gcc-e0c9fbb7638b1d558eab84e981b2347fbf97c59a.tar.bz2
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
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c27
1 files changed, 20 insertions, 7 deletions
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)