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
This commit is contained in:
Joseph Myers 2000-10-25 18:45:44 +01:00 committed by Joseph Myers
parent fb204271dd
commit e0c9fbb763
6 changed files with 77 additions and 7 deletions

View File

@ -1,3 +1,11 @@
2000-10-25 Joseph S. Myers <jsm28@cam.ac.uk>
* 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 <neilb@earthling.net>
* cpp.texi: Update with implementation-defined behavior and

View File

@ -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)

View File

@ -1816,6 +1816,13 @@ that of ordinary mathematical notation.
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.

View File

@ -1,3 +1,7 @@
2000-10-25 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/qual-return-1.c, gcc.dg/qual-return-2.c: New tests.
2000-10-25 Jakub Jelinek <jakub@redhat.com>
* gcc.c-torture/execute/20001024-1.c: New test.

View File

@ -0,0 +1,24 @@
/* Test for warnings for qualified function return types. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { 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" } */

View File

@ -0,0 +1,14 @@
/* Test for warnings for qualified function return types. -pedantic test. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { 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" } */