diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 33cea052eff..e1507651c2b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2009-04-18 Joseph Myers + + PR c/35210 + * c-typeck.c (build_function_call): Check for calling a function + with qualified void return types. Call require_complete_type when + generating a trap. + 2009-04-18 Jan Hubicka * cgraph.c (cgraph_make_edge, dump_cgraph_node, cgraph_set_call_stmt): diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 4b0dbbb8be8..001ea1a5aec 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2498,7 +2498,12 @@ build_function_call (tree function, tree params) trap = build2 (COMPOUND_EXPR, void_type_node, argarray[i], trap); if (VOID_TYPE_P (return_type)) - return trap; + { + if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED) + pedwarn (input_location, 0, + "function with qualified void return type called"); + return trap; + } else { tree rhs; @@ -2510,7 +2515,8 @@ build_function_call (tree function, tree params) else rhs = fold_convert (return_type, integer_zero_node); - return build2 (COMPOUND_EXPR, return_type, trap, rhs); + return require_complete_type (build2 (COMPOUND_EXPR, return_type, + trap, rhs)); } } @@ -2543,7 +2549,12 @@ build_function_call (tree function, tree params) function, nargs, argarray); if (VOID_TYPE_P (TREE_TYPE (result))) - return result; + { + if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED) + pedwarn (input_location, 0, + "function with qualified void return type called"); + return result; + } return require_complete_type (result); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 075c7b56687..16197bc6e83 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-18 Joseph Myers + + PR c/35210 + * gcc.dg/call-diag-2.c: New test. + 2009-04-18 Joseph Myers PR preprocessor/39646 diff --git a/gcc/testsuite/gcc.dg/call-diag-2.c b/gcc/testsuite/gcc.dg/call-diag-2.c new file mode 100644 index 00000000000..0d87e52e973 --- /dev/null +++ b/gcc/testsuite/gcc.dg/call-diag-2.c @@ -0,0 +1,17 @@ +/* Test diagnostics for calling function returning qualified void or + other incomplete type other than void. PR 35210. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors" } */ + +const void f_cv (void); +struct s f_s (void); +void f_v (void); + +void g1 (void) { f_cv (); } /* { dg-error "qualified void" } */ +void g2 (void) { f_s (); } /* { dg-error "invalid use of undefined type" } */ +void g3 (void) { ((const void (*) (void)) f_v) (); } /* { dg-error "qualified void" } */ +/* { dg-warning "function called through a non-compatible type" "cast" { target *-*-* } 12 } */ +/* { dg-message "will abort" "abort" { target *-*-* } 12 } */ +void g4 (void) { ((struct s (*) (void)) f_v) (), (void) 0; } /* { dg-error "invalid use of undefined type" } */ +/* { dg-warning "function called through a non-compatible type" "cast" { target *-*-* } 15 } */ +/* { dg-message "will abort" "abort" { target *-*-* } 15 } */