diff options
author | David Pagan <dave.pagan@oracle.com> | 2018-05-30 22:55:38 +0000 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2018-05-30 16:55:38 -0600 |
commit | b67b9225f72e4b2d58e535c78dbeff83f94c8f66 (patch) | |
tree | bd00a7c76e46ddf69b97e2eb349f2abd1e3a4325 /gcc/c/c-decl.c | |
parent | e91c9fe5008f21f582142bfa8d50481f5991829e (diff) | |
download | gcc-b67b9225f72e4b2d58e535c78dbeff83f94c8f66.zip gcc-b67b9225f72e4b2d58e535c78dbeff83f94c8f66.tar.gz gcc-b67b9225f72e4b2d58e535c78dbeff83f94c8f66.tar.bz2 |
re PR c/55976 (-Werror=return-type should error on returning a value from a void function)
2018-05-30 David Pagan <dave.pagan@oracle.com>
PR c/55976
* c-decl.c (grokdeclarator): Update check for return type warnings.
(start_function): Likewise.
(finish_function): Likewise.
* c-typeck.c (c_finish_return): Update check for return type warnings.
Pass OPT_Wreturn_type to pedwarn when appropriate.
PR c/55976
* c-opts.c (c_common_post_options): Set default for warn_return_type
for C++/C++ with ObjC extensions only. For C, makes it possible to
differentiate between default (no option), -Wreturn-type, and
-Wno-return-type.
PR c/55976
* gcc.dg/noncompile/pr55976-1.c: New test.
* gcc.dg/noncompile/pr55976-2.c: New test.
From-SVN: r260978
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r-- | gcc/c/c-decl.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 3c4b18e..54f58a5 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5758,7 +5758,7 @@ grokdeclarator (const struct c_declarator *declarator, /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type and this is a function, or if -Wimplicit; prefer the former warning since it is more explicit. */ - if ((warn_implicit_int || warn_return_type || flag_isoc99) + if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99) && funcdef_flag) warn_about_return_type = 1; else @@ -8752,7 +8752,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, if (warn_about_return_type) warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int - : (warn_return_type ? OPT_Wreturn_type + : (warn_return_type > 0 ? OPT_Wreturn_type : OPT_Wimplicit_int), "return type defaults to %<int%>"); @@ -9463,8 +9463,9 @@ finish_function (void) finish_fname_decls (); - /* Complain if there's just no return statement. */ - if (warn_return_type + /* Complain if there's no return statement only if option specified on + command line. */ + if (warn_return_type > 0 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE && !current_function_returns_value && !current_function_returns_null /* Don't complain if we are no-return. */ |