c++: Detect long double -> double narrowing [PR94590]
authorMarek Polacek <polacek@redhat.com>
Sun, 19 Apr 2020 22:46:40 +0000 (18:46 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 7 May 2020 18:15:37 +0000 (14:15 -0400)
commit5d5dcc65aae1024da31e0e9cae6a8966461037e8
treefb7af4ad2866a940fc07338d26f5e1ff224325d1
parent21968d4ae067e3fa1c1728c8db26478e8ac8ad0b
c++: Detect long double -> double narrowing [PR94590]

This PR points out that we don't detect long double -> double narrowing
when long double happens to have the same precision as double; on x86_64
this can be achieved by -mlong-double-64.

[dcl.init.list]#7.2 specifically says "from long double to double or float,
or from double to float", but check_narrowing only checks

  TYPE_PRECISION (type) < TYPE_PRECISION (ftype)

so we need to handle the other cases too, e.g. by same_type_p as in
the following patch.

PR c++/94590 - Detect long double -> double narrowing.
* typeck2.c (check_narrowing): Detect long double -> double
narrowing even when double and long double have the same
precision.  Make it handle conversions to float too.

* g++.dg/cpp0x/Wnarrowing18.C: New test.
gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wnarrowing18.C [new file with mode: 0644]