Commit 32e00768 by Marek Polacek Committed by Marek Polacek

re PR c/43395 (Gcc warns label as local variable)

	PR c/43395
c/
	* c-typeck.c (c_finish_return): Distinguish between label and variable
	when warning about returning local address.
cp/
	* typeck.c (maybe_warn_about_returning_address_of_local): Distinguish
	between label and variable when warning about returning local address.
testsuite/
	* c-c++-common/pr43395.c: New test.

From-SVN: r209973
parent 944052b9
2014-05-01 Marek Polacek <polacek@redhat.com>
PR c/43395
* c-typeck.c (c_finish_return): Distinguish between label and variable
when warning about returning local address.
2014-05-01 Marek Polacek <polacek@redhat.com>
PR c/29467
* c-decl.c (declspecs_add_type): Pedwarn if boolean types are used
in C89 mode.
......
......@@ -9265,7 +9265,8 @@ c_finish_return (location_t loc, tree retval, tree origtype)
&& DECL_CONTEXT (inner) == current_function_decl)
warning_at (loc,
OPT_Wreturn_local_addr, "function returns address "
"of local variable");
"of %s", TREE_CODE (inner) == LABEL_DECL
? "label" : "local variable");
break;
default:
......
2014-05-01 Marek Polacek <polacek@redhat.com>
PR c/43395
* typeck.c (maybe_warn_about_returning_address_of_local): Distinguish
between label and variable when warning about returning local address.
2014-04-30 Jason Merrill <jason@redhat.com>
PR c++/60980
......
......@@ -8310,8 +8310,9 @@ maybe_warn_about_returning_address_of_local (tree retval)
warning (OPT_Wreturn_local_addr, "reference to local variable %q+D returned",
whats_returned);
else
warning (OPT_Wreturn_local_addr, "address of local variable %q+D returned",
whats_returned);
warning (OPT_Wreturn_local_addr, "address of %s %q+D returned",
TREE_CODE (whats_returned) == LABEL_DECL
? "label" : "local variable", whats_returned);
return;
}
}
......
2014-05-01 Marek Polacek <polacek@redhat.com>
PR c/43395
* c-c++-common/pr43395.c: New test.
2014-05-01 Yuri Rumyantsev <ysrumyan@gmail.com>
* gcc.dg/cond-reduc-1.c: New test.
......
/* PR c/43395 */
/* { dg-do compile } */
void *
foo (void)
{
lab:
return &&lab;
/* { dg-warning "function returns address of label" "" { target c } 8 } */
/* { dg-warning "address of label" "" { target c++ } 7 } */
}
void *
bar (void)
{
__label__ lab;
lab:
return &&lab;
/* { dg-warning "function returns address of label" "" { target c } 18 } */
/* { dg-warning "address of label" "" { target c++ } 17 } */
}
void *
baz (void)
{
int i;
return &i;
/* { dg-warning "function returns address of local variable" "" { target c } 27 } */
/* { dg-warning "address of local variable" "" { target c++ } 26 } */
}
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