public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marcin Baczyński" <marbacz@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: "Marcin Baczyński" <marbacz@gmail.com>
Subject: [PATCH] Warn about return with a void expression with -Wreturn-type.
Date: Wed, 01 Jun 2016 11:55:00 -0000	[thread overview]
Message-ID: <20160601115504.725560-2-marbacz@gmail.com> (raw)
In-Reply-To: <20160601115504.725560-1-marbacz@gmail.com>

PR c/48116.

Botstrapped and tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:

   * c/c-typeck.c (c_finish_return): emit warning about return with a
    void expression in a function returning void if warn_return_type.

gcc/testsuite/ChangeLog:

   * gcc.dg/Wreturn-type3.c: new test.
---
 gcc/c/c-typeck.c                     | 4 ++++
 gcc/testsuite/gcc.dg/Wreturn-type3.c | 6 ++++++
 2 files changed, 10 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/Wreturn-type3.c

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 1520c20..8ac6cd4 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -9700,6 +9700,10 @@ c_finish_return (location_t loc, tree retval, tree origtype)
 	warned_here = pedwarn
 	  (xloc, 0,
 	   "%<return%> with a value, in function returning void");
+      else if (warn_return_type)
+	warned_here = warning_at
+	  (loc, OPT_Wreturn_type,
+	   "%<return%> with expression, in function returning void");
       else
 	warned_here = pedwarn
 	  (xloc, OPT_Wpedantic, "ISO C forbids "
diff --git a/gcc/testsuite/gcc.dg/Wreturn-type3.c b/gcc/testsuite/gcc.dg/Wreturn-type3.c
new file mode 100644
index 0000000..e83c94b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wreturn-type3.c
@@ -0,0 +1,6 @@
+/* PR c/48116 */
+/* { dg-do compile } */
+/* { dg-options "-Wreturn-type" } */
+
+void a() {}
+void b() { return a(); }  /* { dg-warning "return" "returning void" } */
-- 
2.8.3

  reply	other threads:[~2016-06-01 11:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-01 11:55 [PATCH 1/2] Fix warnings reported with -Wreturn-type after patching PR c/48116 Marcin Baczyński
2016-06-01 11:55 ` Marcin Baczyński [this message]
2016-06-01 12:07   ` [PATCH] Warn about return with a void expression with -Wreturn-type Jakub Jelinek
     [not found]     ` <CALvMQwTZiyrL+KvcFAk20ZYSLk9dDOR+vLJasLhr-C_23WijJA@mail.gmail.com>
2016-06-01 16:39       ` Jakub Jelinek
2016-06-01 17:03         ` Martin Sebor
2016-06-01 18:59           ` Marcin Baczyński
2016-06-02  2:51             ` Martin Sebor
2016-06-02 10:03               ` Marcin Baczyński
2016-06-02 10:03               ` Marcin Baczyński
2016-06-03  9:36                 ` Bernd Schmidt
2016-06-03 10:16                   ` Marcin Baczyński
2016-06-04 20:51                     ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160601115504.725560-2-marbacz@gmail.com \
    --to=marbacz@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).