public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-17 11:59 ` pinskia at gcc dot gnu.org
2021-12-17 13:48 ` redi at gcc dot gnu.org
` (12 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 11:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2021-12-17
Known to fail| |11.2.0, 4.4.7, 4.7.4, 4.9.4
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
2021-12-17 11:59 ` [Bug c++/83264] std::initializer_list with a single element selects the wrong overload pinskia at gcc dot gnu.org
@ 2021-12-17 13:48 ` redi at gcc dot gnu.org
2021-12-17 14:04 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-17 13:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Maybe another case of DR 2137 (PR 85577)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
2021-12-17 11:59 ` [Bug c++/83264] std::initializer_list with a single element selects the wrong overload pinskia at gcc dot gnu.org
2021-12-17 13:48 ` redi at gcc dot gnu.org
@ 2021-12-17 14:04 ` pinskia at gcc dot gnu.org
2021-12-17 14:05 ` pinskia at gcc dot gnu.org
` (10 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 14:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Alias| |Cwg1467
Resolution|--- |INVALID
Status|NEW |RESOLVED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
DR 1467 describes that gcc is correct.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2021-12-17 14:04 ` pinskia at gcc dot gnu.org
@ 2021-12-17 14:05 ` pinskia at gcc dot gnu.org
2021-12-17 16:15 ` sig993m at gmail dot com
` (9 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 14:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://wg21.link/cwg1467
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2021-12-17 14:05 ` pinskia at gcc dot gnu.org
@ 2021-12-17 16:15 ` sig993m at gmail dot com
2021-12-17 17:05 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: sig993m at gmail dot com @ 2021-12-17 16:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #5 from Ruslan Altynbaev <sig993m at gmail dot com> ---
Actually DR 2137 describes that:
https://wg21.link/cwg2137
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2021-12-17 16:15 ` sig993m at gmail dot com
@ 2021-12-17 17:05 ` redi at gcc dot gnu.org
2021-12-17 20:37 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-17 17:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't know what the "right" behaviour is. I don't think any compiler except
GCC actually implements 2137, as it causes problems. I'm not even sure if this
is a case where 2137 applies!
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2021-12-17 17:05 ` redi at gcc dot gnu.org
@ 2021-12-17 20:37 ` pinskia at gcc dot gnu.org
2022-02-04 22:28 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 20:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|1 |0
Resolution|INVALID |---
Status|RESOLVED |UNCONFIRMED
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The example at the end of the change of DR 1467:
Example:
void f1(int); // #1
void f1(std::initializer_list<long>); // #2
void g1() { f1({42}); } // chooses #2
void f2(std::pair<const char*, const char*>); // #3
void f2(std::initializer_list<std::string>); // #4
void g2() { f2({"foo","bar"}); } // chooses #4
—end example]
http://www.open-std.org/cwg1589 is also this one too.
Plus http://www.open-std.org/cwg2076
Note I don't think constructor of A matter, it could be a function instead,
e.g.:
#include <iostream>
#include <initializer_list>
using namespace std;
struct UdfInt {
UdfInt(int) {}
};
void f(int)
{
cout << "f(int)\n";
}
void f(UdfInt)
{
cout << "f(initializer_list)\n";
}
void f(std::initializer_list<UdfInt>)
{
cout << "f(initializer_list)\n";
}
int main() {
f({10});
return 0;
}
GCC prints f(initializer_list) while all the rest of the compilers print
A(int).
The big question initializer_list<UdfInt> a better conversion from
initializer_list<int> than int.
I think the answer is yes.
The example in DR 1467 shows that the conversion from initializer_list<int> to
initializer_list<long> is better than the conversion from initializer_list<int>
to int (clang implements that, ICC and MSVC do not).
I think the language change in end of DR 1467 is what applies here the most:
even if one of the other rules in this paragraph would otherwise apply.
Also if we take:
#include <iostream>
#include <initializer_list>
#include <string>
using namespace std;
#if 0
static void f(const char*)
{
cout << "f(const char*)\n";
}
#endif
static void f(std::string)
{
cout << "f(std::string)\n";
}
static void f(std::initializer_list<std::string>)
{
cout << "f(initializer_list)\n";
}
int main() {
f({"10"});
return 0;
}
Right now all compilers agree f(initializer_list) but once we add in f(const
char*), GCC still selects f(initializer_list) while ICC/MSVC/clang select
f(const char*). That seems a bit odd.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2021-12-17 20:37 ` pinskia at gcc dot gnu.org
@ 2022-02-04 22:28 ` pinskia at gcc dot gnu.org
2022-02-05 8:43 ` fchelnokov at gmail dot com
` (5 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-04 22:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rs2740 at gmail dot com
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 99273 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (7 preceding siblings ...)
2022-02-04 22:28 ` pinskia at gcc dot gnu.org
@ 2022-02-05 8:43 ` fchelnokov at gmail dot com
2022-05-23 10:52 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: fchelnokov at gmail dot com @ 2022-02-05 8:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #9 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
There is a related discussion: https://stackoverflow.com/a/47618530/7325599
And it is noted there that according to [over.ics.rank]/2 just before
[over.ics.rank]/3:
— a standard conversion sequence is a better conversion sequence than a
user-defined conversion
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (8 preceding siblings ...)
2022-02-05 8:43 ` fchelnokov at gmail dot com
@ 2022-05-23 10:52 ` redi at gcc dot gnu.org
2022-12-12 19:22 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-23 10:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jeanmichael.celerier@gmail.
| |com
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 105683 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (9 preceding siblings ...)
2022-05-23 10:52 ` redi at gcc dot gnu.org
@ 2022-12-12 19:22 ` jason at gcc dot gnu.org
2022-12-12 19:24 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2022-12-12 19:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=64665
--- Comment #11 from Jason Merrill <jason at gcc dot gnu.org> ---
I agree with comment #7 that this is DR1467, not 2137. Both deal with the
relative priority of single-element initialization and initializer_list
initialization; 1467 is overload resolution between initializer_list and
something else, 2137 is at a higher level determining how to initialize a class
from a braced-init-list. In this testcase the extra () mean that we aren't
dealing with list-initialization of obj, but rather of the constructor
parameter, so 1467 is the relevant DR.
This is also the same issue as PR64665, where a 2015 comment from Richard Smith
of Clang agrees with my understanding at the time that the initializer_list
tiebreaker takes precedence over everything else. This is consistent with the
effect of 2137--which no other compiler seems to implement yet.
However, I now see that this isn't what the standard actually says: as comment
#9 points out, [over.ics.rank] talks about comparing forms first, and the
initializer_list tiebreaker only applies to conversions of the same form. I
thought of list-initialization as its own form, but the standard doesn't say
that; the three forms are still standard, user-defined, or ellipsis.
I've asked the CWG reflector for input.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (10 preceding siblings ...)
2022-12-12 19:22 ` jason at gcc dot gnu.org
@ 2022-12-12 19:24 ` jason at gcc dot gnu.org
2023-04-15 9:35 ` pinskia at gcc dot gnu.org
2023-12-20 16:21 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2022-12-12 19:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> ---
Created attachment 54076
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54076&action=edit
patch to follow other implementations
Here's the patch if we do want to go that way.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (11 preceding siblings ...)
2022-12-12 19:24 ` jason at gcc dot gnu.org
@ 2023-04-15 9:35 ` pinskia at gcc dot gnu.org
2023-12-20 16:21 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-15 9:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 109523 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/83264] std::initializer_list with a single element selects the wrong overload
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
` (12 preceding siblings ...)
2023-04-15 9:35 ` pinskia at gcc dot gnu.org
@ 2023-12-20 16:21 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2023-12-20 16:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264
--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> ---
Pinged CWG again.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-12-20 16:21 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-83264-4@http.gcc.gnu.org/bugzilla/>
2021-12-17 11:59 ` [Bug c++/83264] std::initializer_list with a single element selects the wrong overload pinskia at gcc dot gnu.org
2021-12-17 13:48 ` redi at gcc dot gnu.org
2021-12-17 14:04 ` pinskia at gcc dot gnu.org
2021-12-17 14:05 ` pinskia at gcc dot gnu.org
2021-12-17 16:15 ` sig993m at gmail dot com
2021-12-17 17:05 ` redi at gcc dot gnu.org
2021-12-17 20:37 ` pinskia at gcc dot gnu.org
2022-02-04 22:28 ` pinskia at gcc dot gnu.org
2022-02-05 8:43 ` fchelnokov at gmail dot com
2022-05-23 10:52 ` redi at gcc dot gnu.org
2022-12-12 19:22 ` jason at gcc dot gnu.org
2022-12-12 19:24 ` jason at gcc dot gnu.org
2023-04-15 9:35 ` pinskia at gcc dot gnu.org
2023-12-20 16:21 ` jason 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).