public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105111] New: Ambiguous constructor overload with requires constraint
@ 2022-03-30 18:14 andrei.popa105 at yahoo dot com
2022-03-30 18:55 ` [Bug c++/105111] " ppalka at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: andrei.popa105 at yahoo dot com @ 2022-03-30 18:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105111
Bug ID: 105111
Summary: Ambiguous constructor overload with requires
constraint
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: andrei.popa105 at yahoo dot com
Target Milestone: ---
Let's consider the following code:
#include <iostream>
#include <type_traits>
struct S {
template <typename T> explicit S(T) noexcept requires
std::is_signed<T>::value {
std::cout << "T\n";
}
template<typename T> explicit S(const T&) noexcept {
std::cout << "const T&\n";
}
};
int main() {
S s(4);
}
To compile this code I used the following command and I provide also a link to
a godbolt instance:
g++ -std=c++23 example.cpp -o example
https://godbolt.org/z/vaGafvKcT
This code doesn't compile with gcc 12.0.
I think this is a bug because the most constrained constructor is the first one
and has a matching requires clause when we create the s object.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/105111] Ambiguous constructor overload with requires constraint
2022-03-30 18:14 [Bug c++/105111] New: Ambiguous constructor overload with requires constraint andrei.popa105 at yahoo dot com
@ 2022-03-30 18:55 ` ppalka at gcc dot gnu.org
2022-03-30 18:59 ` ppalka at gcc dot gnu.org
2022-03-30 19:17 ` andrei.popa105 at yahoo dot com
2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-03-30 18:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105111
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
CC| |ppalka at gcc dot gnu.org
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Andrei-Edward Popa from comment #0)
> I think this is a bug because the most constrained constructor is the first
> one and has a matching requires clause when we create the s object.
According to the standard (http://eel.is/c++draft/temp.func.order#6), "more
constrained" is used as a tiebreaker between two functions only if their
(function and template) parameter lists are equivalent. In your example the
function parameter lists different ('T' vs 'const T&'), so I believe GCC is
correct to reject the call as ambiguous. If other compilers accept it, it's
probably because they don't implement wg21.link/p2113r0 (which changed this
part of the standard).
*** This bug has been marked as a duplicate of bug 96333 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/105111] Ambiguous constructor overload with requires constraint
2022-03-30 18:14 [Bug c++/105111] New: Ambiguous constructor overload with requires constraint andrei.popa105 at yahoo dot com
2022-03-30 18:55 ` [Bug c++/105111] " ppalka at gcc dot gnu.org
@ 2022-03-30 18:59 ` ppalka at gcc dot gnu.org
2022-03-30 19:17 ` andrei.popa105 at yahoo dot com
2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-03-30 18:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105111
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
FWIW one workaround could be to consistently use 'T' or 'const T&' as the first
function parameter for both functions.
Another workaround could be to constrain the second overload with
'(!std::is_signed<T>::value)'.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/105111] Ambiguous constructor overload with requires constraint
2022-03-30 18:14 [Bug c++/105111] New: Ambiguous constructor overload with requires constraint andrei.popa105 at yahoo dot com
2022-03-30 18:55 ` [Bug c++/105111] " ppalka at gcc dot gnu.org
2022-03-30 18:59 ` ppalka at gcc dot gnu.org
@ 2022-03-30 19:17 ` andrei.popa105 at yahoo dot com
2 siblings, 0 replies; 4+ messages in thread
From: andrei.popa105 at yahoo dot com @ 2022-03-30 19:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105111
--- Comment #3 from Andrei-Edward Popa <andrei.popa105 at yahoo dot com> ---
Thanks for that reference to the standard, it is clear to me why gcc reject
this call as ambiguous.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-30 19:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30 18:14 [Bug c++/105111] New: Ambiguous constructor overload with requires constraint andrei.popa105 at yahoo dot com
2022-03-30 18:55 ` [Bug c++/105111] " ppalka at gcc dot gnu.org
2022-03-30 18:59 ` ppalka at gcc dot gnu.org
2022-03-30 19:17 ` andrei.popa105 at yahoo dot com
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).