This patch fixes handlng of -Werror=return-type. Currently, even with the flag specified, return type errors remain warnings.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55976

Function c_finish_return (), when calling pedwarn, should specifiy OPT_Wreturn_type as the diagnostic index if warn_return_type is set so that the given diagnostic is generated as an error, not a warning.

Patch was successfully bootstrapped and tested on x86_64-linux.

--Dave


/c
2018-04-03  David Pagan  <dave.pa...@oracle.com>

        PR c/55976
        * c-typeck.c (c_finish_return): If -Wreturn-type enabled
        (warn_return_type), pass OPT_Wreturn_type to pedwarn so warning is
        turned into an error when -Werror=return-type specified.

/testsuite
2018-04-03  David Pagan  <dave.pa...@oracle.com>

        PR c/55976
        * gcc.dg/noncompile/pr55976.c: New test.
Index: gcc/c/c-typeck.c
===================================================================
--- gcc/c/c-typeck.c    (revision 259017)
+++ gcc/c/c-typeck.c    (working copy)
@@ -10135,7 +10135,7 @@ c_finish_return (location_t loc, tree retval, tree
          bool warned_here;
          if (flag_isoc99)
            warned_here = pedwarn
-             (loc, 0,
+             (loc, warn_return_type ? OPT_Wreturn_type : 0,
               "%<return%> with no value, in function returning non-void");
          else
            warned_here = warning_at
@@ -10153,7 +10153,7 @@ c_finish_return (location_t loc, tree retval, tree
       bool warned_here;
       if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
        warned_here = pedwarn
-         (xloc, 0,
+         (xloc, warn_return_type ? OPT_Wreturn_type : 0,
           "%<return%> with a value, in function returning void");
       else
        warned_here = pedwarn
Index: gcc/testsuite/gcc.dg/noncompile/pr55976.c
===================================================================
--- gcc/testsuite/gcc.dg/noncompile/pr55976.c   (revision 0)
+++ gcc/testsuite/gcc.dg/noncompile/pr55976.c   (working copy)
@@ -0,0 +1,12 @@
+/* PR c/55976 */
+/* { dg-do compile } */
+/* { dg-options "-Werror=return-type" } */
+
+void t () { return 1; } /* { dg-error "return" "function returning void" } */
+int b () { return; } /* { dg-error "return" "function returning non-void" } */
+
+int main()
+{
+  t(); b();
+  return 0;
+}

Reply via email to