* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
@ 2020-04-14 10:15 ` redi at gcc dot gnu.org
2020-04-15 8:42 ` dangelog at gmail dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-14 10:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2020-04-14
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Giuseppe D'Angelo from comment #0)
> +++ This bug was initially created as a clone of Bug #92856 +++
>
> (Sorry, couldn't find a way to reopen _that_ bug, so creating a new one)
Good, it's not the same bug. That one said we should give an error not a
warning, which is wrong.
This one says we should give a diagnostic irrespective of target, which is
correct.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
2020-04-14 10:15 ` [Bug c++/94590] " redi at gcc dot gnu.org
@ 2020-04-15 8:42 ` dangelog at gmail dot com
2020-04-19 17:05 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: dangelog at gmail dot com @ 2020-04-15 8:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
--- Comment #2 from Giuseppe D'Angelo <dangelog at gmail dot com> ---
A direct effect of this in SFINAE contexts seems to be the implementation of
P0608 (A sane variant converting constructor) that has landed in libstdc++ in
10.1.
This code:
struct S {
S(long double) {}
};
std::variant<double, S> v;
v = 1.0L;
assert(v.index() == 1);
fails the assert if long double is the same as double; works otherwise.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
2020-04-14 10:15 ` [Bug c++/94590] " redi at gcc dot gnu.org
2020-04-15 8:42 ` dangelog at gmail dot com
@ 2020-04-19 17:05 ` mpolacek at gcc dot gnu.org
2020-04-19 17:32 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-19 17:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is because in check_narrowing we have:
1011 else if (TREE_CODE (ftype) == REAL_TYPE
1012 && TREE_CODE (type) == REAL_TYPE)
1013 {
1014 if (TYPE_PRECISION (type) < TYPE_PRECISION (ftype))
...
1027 ok = false;
but with -mlong-double-64 both type and ftype's precision is 64.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
` (2 preceding siblings ...)
2020-04-19 17:05 ` mpolacek at gcc dot gnu.org
@ 2020-04-19 17:32 ` mpolacek at gcc dot gnu.org
2020-04-20 19:40 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-19 17:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Untested fix:
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1008,10 +1008,17 @@ check_narrowing (tree type, tree init, tsubst_flags_t
complain,
|| !int_fits_type_p (init, type)))
ok = false;
}
+ /* [dcl.init.list]#7.2: "from long double to double or float, or from
+ double to float". */
else if (TREE_CODE (ftype) == REAL_TYPE
&& TREE_CODE (type) == REAL_TYPE)
{
- if (TYPE_PRECISION (type) < TYPE_PRECISION (ftype))
+ if ((same_type_p (ftype, long_double_type_node)
+ && (same_type_p (type, double_type_node)
+ || same_type_p (type, float_type_node)))
+ || (same_type_p (ftype, double_type_node)
+ && same_type_p (type, float_type_node))
+ || (TYPE_PRECISION (type) < TYPE_PRECISION (ftype)))
{
if (TREE_CODE (init) == REAL_CST)
{
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
` (3 preceding siblings ...)
2020-04-19 17:32 ` mpolacek at gcc dot gnu.org
@ 2020-04-20 19:40 ` mpolacek at gcc dot gnu.org
2020-05-07 18:16 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-20 19:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch approved for GCC 11:
<https://gcc.gnu.org/pipermail/gcc-patches/2020-April/544146.html>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
` (4 preceding siblings ...)
2020-04-20 19:40 ` mpolacek at gcc dot gnu.org
@ 2020-05-07 18:16 ` cvs-commit at gcc dot gnu.org
2020-05-07 18:18 ` mpolacek at gcc dot gnu.org
2020-05-07 23:35 ` dangelog at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-07 18:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:5d5dcc65aae1024da31e0e9cae6a8966461037e8
commit r11-176-g5d5dcc65aae1024da31e0e9cae6a8966461037e8
Author: Marek Polacek <polacek@redhat.com>
Date: Sun Apr 19 18:46:40 2020 -0400
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
` (5 preceding siblings ...)
2020-05-07 18:16 ` cvs-commit at gcc dot gnu.org
@ 2020-05-07 18:18 ` mpolacek at gcc dot gnu.org
2020-05-07 23:35 ` dangelog at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-07 18:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 11.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/94590] Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double)
2020-04-14 8:59 [Bug c++/94590] New: Incorrectly accepts invalid C++11 braced initialisation of double from long double if sizeof(long double)==sizeof(double) dangelog at gmail dot com
` (6 preceding siblings ...)
2020-05-07 18:18 ` mpolacek at gcc dot gnu.org
@ 2020-05-07 23:35 ` dangelog at gmail dot com
7 siblings, 0 replies; 9+ messages in thread
From: dangelog at gmail dot com @ 2020-05-07 23:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94590
--- Comment #8 from Giuseppe D'Angelo <dangelog at gmail dot com> ---
Thank you!
^ permalink raw reply [flat|nested] 9+ messages in thread