Commit de8ddd5f by Marek Polacek Committed by Marek Polacek

re PR c/67730 (No warning when returning NULL in void function)

	PR c/67730
	* c-typeck.c (c_finish_return): Use the expansion point location for
	certain "return with value" warnings.

	* gcc.dg/pr67730.c: New test.

From-SVN: r228286
parent 6ea2f74c
2015-09-30 Marek Polacek <polacek@redhat.com>
PR c/67730
* c-typeck.c (c_finish_return): Use the expansion point location for
certain "return with value" warnings.
2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org>
* c-parser.c (pragma_lex): Add loc argument.
......
......@@ -9369,8 +9369,12 @@ c_finish_return (location_t loc, tree retval, tree origtype)
bool npc = false;
size_t rank = 0;
/* Use the expansion point to handle cases such as returning NULL
in a function returning void. */
source_location xloc = expansion_point_location_if_in_system_header (loc);
if (TREE_THIS_VOLATILE (current_function_decl))
warning_at (loc, 0,
warning_at (xloc, 0,
"function declared %<noreturn%> has a %<return%> statement");
if (flag_cilkplus && contains_array_notation_expr (retval))
......@@ -9425,10 +9429,10 @@ c_finish_return (location_t loc, tree retval, tree origtype)
{
current_function_returns_null = 1;
if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
pedwarn (loc, 0,
pedwarn (xloc, 0,
"%<return%> with a value, in function returning void");
else
pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
pedwarn (xloc, OPT_Wpedantic, "ISO C forbids "
"%<return%> with expression, in function returning void");
}
else
......
2015-09-30 Marek Polacek <polacek@redhat.com>
PR c/67730
* gcc.dg/pr67730.c: New test.
2015-09-30 Marek Polacek <polacek@redhat.com>
PR tree-optimization/67690
* gcc.dg/torture/pr67690.c: New test.
......
/* PR c/67730 */
/* { dg-do compile } */
/* { dg-options "" } */
#include <stddef.h>
void
fn1 (void)
{
return NULL; /* { dg-warning "10:.return. with a value" } */
}
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