]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-decl.c (grokdeclarator): Move warning for qualified void return types with -pedanti...
authorJoseph Myers <jsm28@cam.ac.uk>
Wed, 25 Oct 2000 17:45:44 +0000 (18:45 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 25 Oct 2000 17:45:44 +0000 (18:45 +0100)
* 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
gcc/c-decl.c
gcc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/qual-return-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/qual-return-2.c [new file with mode: 0644]

index c605f67dd9872557429e851fbd0d090ea200e889..1e708d93ec6b354366365f0dffbbc47c92b60df4 100644 (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
index 00e7b910d727892401c7f2cc41bc0f50a1a90bd7..51d76c5314225877d48549e545cfd0df721fd986 100644 (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)
index 73dd1d9c85b0146692ecffcb5733df1bae655e03..bc05406219bc829da50423607875cbe3d6e6279b 100644 (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.
index f61fb4eac022e1668e1ec11f8b1a224f1911a40a..3c75d3c2ddf94bb2c45e06298111a9d21f38e97e 100644 (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.
diff --git a/gcc/testsuite/gcc.dg/qual-return-1.c b/gcc/testsuite/gcc.dg/qual-return-1.c
new file mode 100644 (file)
index 0000000..5cab75c
--- /dev/null
@@ -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" } */
diff --git a/gcc/testsuite/gcc.dg/qual-return-2.c b/gcc/testsuite/gcc.dg/qual-return-2.c
new file mode 100644 (file)
index 0000000..272787e
--- /dev/null
@@ -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" } */