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
This commit is contained in:
parent
6ea2f74cf9
commit
de8ddd5fb1
@ -1,3 +1,9 @@
|
||||
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
|
||||
|
@ -1,3 +1,8 @@
|
||||
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
|
||||
|
11
gcc/testsuite/gcc.dg/pr67730.c
Normal file
11
gcc/testsuite/gcc.dg/pr67730.c
Normal file
@ -0,0 +1,11 @@
|
||||
/* PR c/67730 */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "" } */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void
|
||||
fn1 (void)
|
||||
{
|
||||
return NULL; /* { dg-warning "10:.return. with a value" } */
|
||||
}
|
Loading…
Reference in New Issue
Block a user