public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110594] New: std::variant's converting constructor does not resolve alternative correctly
@ 2023-07-08 7:03 xgao at nvidia dot com
2023-07-08 7:22 ` [Bug libstdc++/110594] " redi at gcc dot gnu.org
2023-07-08 7:25 ` redi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: xgao at nvidia dot com @ 2023-07-08 7:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110594
Bug ID: 110594
Summary: std::variant's converting constructor does not resolve
alternative correctly
Product: gcc
Version: 13.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: xgao at nvidia dot com
Target Milestone: ---
Created attachment 55502
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55502&action=edit
minimum repro
According to https://en.cppreference.com/w/cpp/utility/variant/variant, I would
expect the attached program to output:
int64_t: 1
variant is int
However, I am getting:
int64_t: 1
variant is complex
gcc-9 seems to have the correct behavior for the attached program, however, the
implementation of std::variant in gcc-9 has another problem that the following
example in that cppreference.com page does not work:
std::variant<float, long, double> z = 0; // OK, holds long
// float and double are not candidates
Thanks to the help of jjsjann123 (https://github.com/jjsjann123), this is
potentially related to the SFINAE in the "variant" header:
// Helper used to check for valid conversions that don't involve narrowing.
template<typename _Ti> struct _Arr { _Ti _M_x[1]; };
seems that this will block int64_t from being selected as shown in
https://godbolt.org/z/Gcr4j53rd. However, the following code is totally valid:
int64_t x[] = {size_t(1)};
so probably that SFINAE might be wrong.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/110594] std::variant's converting constructor does not resolve alternative correctly
2023-07-08 7:03 [Bug libstdc++/110594] New: std::variant's converting constructor does not resolve alternative correctly xgao at nvidia dot com
@ 2023-07-08 7:22 ` redi at gcc dot gnu.org
2023-07-08 7:25 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-08 7:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110594
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
converting a size_t to int64_t is a narrowing conversion, try it without a
constant value and you'll get an error: https://godbolt.org/z/rb6jrr4xq
That's what the SFINAE check for _Arr does, so your {size_t(1)} is not
equivalent and your assumptions based on that are incorrect.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/110594] std::variant's converting constructor does not resolve alternative correctly
2023-07-08 7:03 [Bug libstdc++/110594] New: std::variant's converting constructor does not resolve alternative correctly xgao at nvidia dot com
2023-07-08 7:22 ` [Bug libstdc++/110594] " redi at gcc dot gnu.org
@ 2023-07-08 7:25 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-08 7:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110594
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think libstdc++ is correct here.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-08 7:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-08 7:03 [Bug libstdc++/110594] New: std::variant's converting constructor does not resolve alternative correctly xgao at nvidia dot com
2023-07-08 7:22 ` [Bug libstdc++/110594] " redi at gcc dot gnu.org
2023-07-08 7:25 ` redi at gcc dot gnu.org
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).