Skip to content

Commit

Permalink
PR c/80892 - -Wfloat-conversion now warns about non-floats
Browse files Browse the repository at this point in the history
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.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248852 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
msebor committed Jun 3, 2017
1 parent c37584b commit a977cac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions gcc/c-family/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2017-06-02 Martin Sebor <msebor@redhat.com>

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

2017-06-02 Bernd Edlinger <bernd.edlinger@hotmail.de>

* c.opt (Wsizeof-pointer-div): New warning option.
Expand Down
17 changes: 13 additions & 4 deletions gcc/c-family/c-warn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions gcc/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-06-02 Martin Sebor <msebor@redhat.com>

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

2017-06-02 Paolo Carlini <paolo.carlini@oracle.com>

PR c++/68754
Expand Down

0 comments on commit a977cac

Please sign in to comment.