aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-typeck.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-12-17 21:25:36 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-12-17 21:25:36 +0000
commit94c40e19af4ca5fe57c990df7f7abec48f5aa3af (patch)
tree4c095463412043a04cc04af52d434df35a82c396 /gcc/c/c-typeck.c
parente357a5e03c2e6f3b1d51bebe3c57322b28950b0f (diff)
downloadgcc-94c40e19af4ca5fe57c990df7f7abec48f5aa3af.zip
gcc-94c40e19af4ca5fe57c990df7f7abec48f5aa3af.tar.gz
gcc-94c40e19af4ca5fe57c990df7f7abec48f5aa3af.tar.bz2
C FE: improvements to ranges of bad return values
gcc/c/ChangeLog: * c-parser.c (c_parser_statement_after_labels): When calling c_finish_return, Use the return expression's location if it has one, falling back to the location of the first token within it. * c-typeck.c (c_finish_return): When issuing warnings about the incorrect presence/absence of a return value, issue a note showing the declaration of the function. gcc/testsuite/ChangeLog: * gcc.dg/diagnostic-range-bad-return.c: New test case. From-SVN: r231786
Diffstat (limited to 'gcc/c/c-typeck.c')
-rw-r--r--gcc/c/c-typeck.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index a147ac6..b605f81 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -9545,24 +9545,36 @@ c_finish_return (location_t loc, tree retval, tree origtype)
if ((warn_return_type || flag_isoc99)
&& valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
{
+ bool warned_here;
if (flag_isoc99)
- pedwarn (loc, 0, "%<return%> with no value, in "
- "function returning non-void");
+ warned_here = pedwarn
+ (loc, 0,
+ "%<return%> with no value, in function returning non-void");
else
- warning_at (loc, OPT_Wreturn_type, "%<return%> with no value, "
- "in function returning non-void");
+ warned_here = warning_at
+ (loc, OPT_Wreturn_type,
+ "%<return%> with no value, in function returning non-void");
no_warning = true;
+ if (warned_here)
+ inform (DECL_SOURCE_LOCATION (current_function_decl),
+ "declared here");
}
}
else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
{
current_function_returns_null = 1;
+ bool warned_here;
if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
- pedwarn (xloc, 0,
- "%<return%> with a value, in function returning void");
+ warned_here = pedwarn
+ (xloc, 0,
+ "%<return%> with a value, in function returning void");
else
- pedwarn (xloc, OPT_Wpedantic, "ISO C forbids "
- "%<return%> with expression, in function returning void");
+ warned_here = pedwarn
+ (xloc, OPT_Wpedantic, "ISO C forbids "
+ "%<return%> with expression, in function returning void");
+ if (warned_here)
+ inform (DECL_SOURCE_LOCATION (current_function_decl),
+ "declared here");
}
else
{