public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Gcc Patch List <gcc-patches@gcc.gnu.org>,
	Joseph Myers <joseph@codesourcery.com>
Subject: [PATCH] use the right conversion warning option (PR c/80892)
Date: Tue, 30 May 2017 19:54:00 -0000	[thread overview]
Message-ID: <37d08c31-3643-0cb7-18e5-24d477a53dd8@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 189 bytes --]

The conversion enhancements I committed in r248431 introduced
an unintended change in which warning option is used to issue
certain integer conversion warnings.  Attached is a fix.

Martin

[-- Attachment #2: gcc-80892.diff --]
[-- Type: text/x-patch, Size: 1897 bytes --]

PR c/80892 - -Wfloat-conversion now warns about non-floats

gcc/c-family/ChangeLog:

	PR c/80892
	* c-warn.c (conversion_warning): Use -Wconversion for integer
	conversion and -Wfloat-conversion for floating one.

gcc/testsuite/ChangeLog:

	PR c/80892
	* c-c++-common/Wfloat-conversion-2.c: New test.

diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 012675b..35321a6 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -1043,10 +1043,19 @@ conversion_warning (location_t loc, tree type, tree expr, tree result)
 		    "conversion from %qT to to %qT discards imaginary "
 		    "component",
 		    expr_type, type);
-      else if (conversion_kind == UNSAFE_REAL || conversion_kind)
-	warning_at (loc, OPT_Wfloat_conversion,
-		    "conversion from %qT to %qT may change value",
-		    expr_type, type);
+      else
+	{
+	  int warnopt;
+	  if (conversion_kind == UNSAFE_REAL)
+	    warnopt = OPT_Wfloat_conversion;
+	  else if (conversion_kind)
+	    warnopt = OPT_Wconversion;
+	  else
+	    break;
+	  warning_at (loc, warnopt,
+		      "conversion from %qT to %qT may change value",
+		      expr_type, type);
+	}
     }
 }
 
diff --git a/gcc/testsuite/c-c++-common/Wfloat-conversion-2.c b/gcc/testsuite/c-c++-common/Wfloat-conversion-2.c
new file mode 100644
index 0000000..626e35b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wfloat-conversion-2.c
@@ -0,0 +1,19 @@
+/* PR c/80892 - [8 regression] -Wfloat-conversion now warns about non-floats
+   { dg-do compile }
+   { dg-options "-Wconversion -Wfloat-conversion" }
+   { dg-require-effective-target int32plus }
+   { dg-require-effective-target double64plus } */
+
+void fschar (char);
+
+void fulong (unsigned long x)
+{
+  fschar (x);   /* { dg-warning "\\[-Wconversion\\]" } */
+}
+
+void ffloat (float);
+
+void fdouble (double x)
+{
+  ffloat (x);   /* { dg-warning "\\[-Wfloat-conversion\\]" } */
+}

             reply	other threads:[~2017-05-30 19:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-30 19:54 Martin Sebor [this message]
2017-06-02  0:38 ` Eric Gallager
2017-06-02 14:33   ` Martin Sebor
2017-06-03  2:51     ` [committed] " 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=37d08c31-3643-0cb7-18e5-24d477a53dd8@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /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).