This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Emit warning for function declaration with qualified void return type


This patch enables pedantic warning, in c99 mode, for function declarations that has qualified void return type. GCC already emits warning for function definitions.

2004-01-04 Devang Patel <dpatel@apple.com>

        * c-decl.c (grokdeclarator): In c99 mode when function
        declaration has qualified void return type, emit pedantic
        warning.

        * gcc.dg/qual-return-1.c: Update warning message.
        * gcc.dg/vmx/t.c: Same.
        * gcc.dg/qual-return-5.c: New test.


Bootstrapped and tested on powerpc-darwin. This is a regression from earlier GCC.

OK?
-
Devang

Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.619
diff -Idpatel.pbxuser -c -3 -p -r1.619 c-decl.c
*** gcc/c-decl.c 21 Dec 2004 17:06:25 -0000 1.619
--- gcc/c-decl.c 4 Jan 2005 19:25:24 -0000
*************** grokdeclarator (const struct c_declarato
*** 4182,4189 ****
Qualifiers on a void return type are banned on
function definitions in ISO C; GCC used to used
them for noreturn functions. */
! if (VOID_TYPE_P (type) && really_funcdef)
! pedwarn ("function definition has qualified void return type");
else if (warn_return_type)
warning ("type qualifiers ignored on function return type");


--- 4182,4193 ----
Qualifiers on a void return type are banned on
function definitions in ISO C; GCC used to used
them for noreturn functions. */
! if (VOID_TYPE_P (type)) {
! if (really_funcdef)
! pedwarn ("function definition has qualified void return type");
! else if (flag_isoc99)
! pedwarn ("function declaration has qualified void return type");
! }
else if (warn_return_type)
warning ("type qualifiers ignored on function return type");


Index: gcc/testsuite/gcc.dg/qual-return-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/qual-return-1.c,v
retrieving revision 1.2
diff -Idpatel.pbxuser -c -3 -p -r1.2 qual-return-1.c
*** gcc/testsuite/gcc.dg/qual-return-1.c 22 Jul 2004 00:00:47 -0000 1.2
--- gcc/testsuite/gcc.dg/qual-return-1.c 4 Jan 2005 19:25:29 -0000
*************** const int int_fn (void); /* { dg-warning
*** 9,20 ****
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 "qualified" "void defn" } */


! volatile void vvoid_fn (void); /* { dg-warning "qualifiers" "void decl" } */
! volatile void (*vvoid_ptr) (void); /* { dg-warning "qualifiers" "void ptr" } */
volatile void vvoid_fn2 (void) { } /* { dg-warning "qualified" "void defn" } */


int *restrict ip_fn (void); /* { dg-warning "qualifiers" "restrict decl" } */
--- 9,20 ----
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 "qualified" "void decl" } */
! const void (*void_ptr) (void); /* { dg-warning "qualified" "void ptr" } */
const void void_fn2 (void) { } /* { dg-warning "qualified" "void defn" } */


! volatile void vvoid_fn (void); /* { dg-warning "qualified" "void decl" } */
! volatile void (*vvoid_ptr) (void); /* { dg-warning "qualified" "void ptr" } */
volatile void vvoid_fn2 (void) { } /* { dg-warning "qualified" "void defn" } */


int *restrict ip_fn (void); /* { dg-warning "qualifiers" "restrict decl" } */
Index: gcc/testsuite/gcc.dg/vmx/t.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/vmx/t.c,v
retrieving revision 1.1
diff -Idpatel.pbxuser -c -3 -p -r1.1 t.c
*** gcc/testsuite/gcc.dg/vmx/t.c 18 Apr 2004 01:01:41 -0000 1.1
--- gcc/testsuite/gcc.dg/vmx/t.c 4 Jan 2005 19:25:30 -0000
*************** vector pixel T_vec_p16;
*** 39,43 ****
vector bool int T_vec_b32;
vector bool char T_vec_b8;
float T_float;
! volatile void g(void);
const char *T_const_char_ptr;
--- 39,43 ----
vector bool int T_vec_b32;
vector bool char T_vec_b8;
float T_float;
! volatile void g(void); /* { dg-warning "qualified" "void decl" } */
const char *T_const_char_ptr;


Index: gcc/testsuite/gcc.dg/qual-return-5.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/qual-return-5.c
diff -N gcc/testsuite/gcc.dg/qual-return-5.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/gcc.dg/qual-return-5.c 3 Jan 2005 23:27:07 -0000
***************
*** 0 ****
--- 1,10 ----
+ /* Test for warnings for qualified function return types. */
+ /* { dg-do compile } */
+ /* { dg-options "-std=gnu99" } */
+
+ /* Qualifying a function return type makes no sense. */
+
+ 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 "qualified" "void defn" } */
+



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]