diff options
author | Joseph Myers <joseph@codesourcery.com> | 2009-04-18 21:02:47 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2009-04-18 21:02:47 +0100 |
commit | 3ce6296587139c291f7f5c31dbdc30e9c2e1829f (patch) | |
tree | a6c65f5de5128a6789a87a6fcc619e69296cae6e | |
parent | 2daad65eaf4b3406d04d6ba4758b120312ed0a0c (diff) | |
download | gcc-3ce6296587139c291f7f5c31dbdc30e9c2e1829f.zip gcc-3ce6296587139c291f7f5c31dbdc30e9c2e1829f.tar.gz gcc-3ce6296587139c291f7f5c31dbdc30e9c2e1829f.tar.bz2 |
re PR c/35210 (gcc incorrectly allows calling function returning "const void")
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.
testsuite:
* gcc.dg/call-diag-2.c: New test.
From-SVN: r146324
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-typeck.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/call-diag-2.c | 17 |
4 files changed, 43 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 33cea05..e150765 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2009-04-18 Joseph Myers <joseph@codesourcery.com> + + 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 <jh@suse.cz> * 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 4b0dbbb..001ea1a 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 075c7b5..16197bc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2009-04-18 Joseph Myers <joseph@codesourcery.com> + PR c/35210 + * gcc.dg/call-diag-2.c: New test. + +2009-04-18 Joseph Myers <joseph@codesourcery.com> + PR preprocessor/39646 * gcc.dg/cpp/line8.c: New test. 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 0000000..0d87e52 --- /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 } */ |