Commit 3ce62965 by Joseph Myers Committed by Joseph Myers

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
parent 2daad65e
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):
......
......@@ -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);
}
......
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.
......
/* 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 } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment