]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Add -Wreturn-mismatch warning, split from -Wreturn-type
authorFlorian Weimer <fweimer@redhat.com>
Thu, 9 Nov 2023 08:50:54 +0000 (09:50 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 9 Nov 2023 08:53:40 +0000 (09:53 +0100)
commit6e312b2b864bf923a9d772429f014375bf9dabc8
tree42a9ab533a216f375efd9dbd5163482fe4738af8
parentf88b78b1196d71042cf129be7a0bf02b9a4de0d3
c: Add -Wreturn-mismatch warning, split from -Wreturn-type

The existing -Wreturn-type option covers both constraint violations
(which are mandatory to diagnose) and warnings that have known
false positives.  The new -Wreturn-mismatch warning is only about
the constraint violations (missing or extra return expressions),
and should eventually be turned into a permerror.

The -std=gnu89 test cases show that by default, we do not warn for
return; in a function not returning void.  This matches previous
practice for -Wreturn-type.

gcc/c-family/

* c.opt (Wreturn-mismatch): New.

gcc/c/

* c-typeck.cc (c_finish_return): Use pedwarn with
OPT_Wreturn_mismatch for missing/extra return expressions.

gcc/

* doc/invoke.texi (Warning Options): Document
-Wreturn-mismatch.  Update -Wreturn-type documentation.

gcc/testsuite/

* gcc.dg/Wreturn-mismatch-1.c: New.
* gcc.dg/Wreturn-mismatch-2.c: New.
* gcc.dg/Wreturn-mismatch-3.c: New.
* gcc.dg/Wreturn-mismatch-4.c: New.
* gcc.dg/Wreturn-mismatch-5.c: New.
* gcc.dg/Wreturn-mismatch-6.c: New.
* gcc.dg/noncompile/pr55976-1.c: Change -Werror=return-type
to -Werror=return-mismatch.
* gcc.dg/noncompile/pr55976-2.c: Change -Wreturn-type
to -Wreturn-mismatch.
gcc/c-family/c.opt
gcc/c/c-typeck.cc
gcc/doc/invoke.texi
gcc/testsuite/gcc.dg/Wreturn-mismatch-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wreturn-mismatch-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wreturn-mismatch-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wreturn-mismatch-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wreturn-mismatch-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/noncompile/pr55976-1.c
gcc/testsuite/gcc.dg/noncompile/pr55976-2.c