public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99963] New: [concepts] template <concept> vs concept auto reports ambiguous overload
@ 2021-04-07 20:02 ldalessandro at gmail dot com
  2021-04-14 15:41 ` [Bug c++/99963] [11 Regression] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ldalessandro at gmail dot com @ 2021-04-07 20:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99963

            Bug ID: 99963
           Summary: [concepts] template <concept> vs concept auto reports
                    ambiguous overload
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldalessandro at gmail dot com
  Target Milestone: ---

Consider the following code (https://godbolt.org/z/h1bz1qxan).

#include <concepts>

struct A{};
struct B : A {};

template <class T> 
concept is_a = std::is_base_of_v<A, T>;

template <class T>
concept is_b = is_a<T> and std::same_as<B, T>;

int foo(is_a auto, is_a auto);

#ifdef OK
int foo(is_b auto, is_a auto);
#else
template <is_a A>
int foo(is_b auto, A);
#endif

A a;
B b;
int d = foo(b, a);

<source>:23:12: error: call of overloaded 'foo(B&, A&)' is ambiguous
   23 | int d = foo(b, a);
      |         ~~~^~~~~~

With -DOK, which enables is_a auto syntax, this compiles. The template <is_a>
fails.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99963] [11 Regression] [concepts] template <concept> vs concept auto reports ambiguous overload
  2021-04-07 20:02 [Bug c++/99963] New: [concepts] template <concept> vs concept auto reports ambiguous overload ldalessandro at gmail dot com
@ 2021-04-14 15:41 ` ppalka at gcc dot gnu.org
  2021-04-14 19:12 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-14 15:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99963

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
   Target Milestone|---                         |11.0
            Summary|[concepts] template         |[11 Regression] [concepts]
                   |<concept> vs concept auto   |template <concept> vs
                   |reports ambiguous overload  |concept auto reports
                   |                            |ambiguous overload

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r11-1571.  Reduced testcase that replaces the abbreviated function
templates with their corresponding non-abbreviated forms:

template <class T> concept C1 = true;
template <class T> concept C2 = C1<T> && true;

template <C1 T, C1 U> int f(T, U);
template <C1 T, C2 U> int f(U, T);

int x = f(0, 0); // error: ambiguous call


If I understand the wording of P2113 correctly:

  If deduction against the other template succeeds for both transformed
templates, constraints can be considered as follows:
  - ... if the corresponding template-parameters of the
template-parameter-lists are not equivalent ([temp.over.link]) or if the
function parameters that positionally correspond between the two templates are
not of the same type, neither template is more specialized than the other

then I think we're correct to reject the call as ambiguous because although the
second overload is more constrained than the first, their function parameter
lists aren't equivalent.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99963] [11 Regression] [concepts] template <concept> vs concept auto reports ambiguous overload
  2021-04-07 20:02 [Bug c++/99963] New: [concepts] template <concept> vs concept auto reports ambiguous overload ldalessandro at gmail dot com
  2021-04-14 15:41 ` [Bug c++/99963] [11 Regression] " ppalka at gcc dot gnu.org
@ 2021-04-14 19:12 ` jason at gcc dot gnu.org
  2021-04-15 14:26 ` ldalessandro at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2021-04-14 19:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99963

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #1)

Yes.  The problem is that you're mixing up which template parameter goes with
which function parameter.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99963] [11 Regression] [concepts] template <concept> vs concept auto reports ambiguous overload
  2021-04-07 20:02 [Bug c++/99963] New: [concepts] template <concept> vs concept auto reports ambiguous overload ldalessandro at gmail dot com
  2021-04-14 15:41 ` [Bug c++/99963] [11 Regression] " ppalka at gcc dot gnu.org
  2021-04-14 19:12 ` jason at gcc dot gnu.org
@ 2021-04-15 14:26 ` ldalessandro at gmail dot com
  2022-06-21 21:21 ` tabloid.adroit at gmail dot com
  2022-06-23 18:47 ` tabloid.adroit at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: ldalessandro at gmail dot com @ 2021-04-15 14:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99963

--- Comment #3 from Luke Dalessandro <ldalessandro at gmail dot com> ---
I understand. Thank you (I've forwarded this on to clang, which _does_ accept
the ambiguous form).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99963] [11 Regression] [concepts] template <concept> vs concept auto reports ambiguous overload
  2021-04-07 20:02 [Bug c++/99963] New: [concepts] template <concept> vs concept auto reports ambiguous overload ldalessandro at gmail dot com
                   ` (2 preceding siblings ...)
  2021-04-15 14:26 ` ldalessandro at gmail dot com
@ 2022-06-21 21:21 ` tabloid.adroit at gmail dot com
  2022-06-23 18:47 ` tabloid.adroit at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: tabloid.adroit at gmail dot com @ 2022-06-21 21:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99963

tabloid.adroit at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tabloid.adroit at gmail dot com

--- Comment #4 from tabloid.adroit at gmail dot com ---
(In reply to Patrick Palka from comment #1)
> Started with r11-1571.  Reduced testcase that replaces the abbreviated
> function templates with their corresponding non-abbreviated forms:
> 
> template <class T> concept C1 = true;
> template <class T> concept C2 = C1<T> && true;
> 
> template <C1 T, C1 U> int f(T, U);
> template <C1 T, C2 U> int f(U, T);
> 
> int x = f(0, 0); // error: ambiguous call
> 
> 
> If I understand the wording of P2113 correctly:
> 
>   If deduction against the other template succeeds for both transformed
> templates, constraints can be considered as follows:
>   - ... if the corresponding template-parameters of the
> template-parameter-lists are not equivalent ([temp.over.link]) or if the
> function parameters that positionally correspond between the two templates
> are not of the same type, neither template is more specialized than the other
> 
> then I think we're correct to reject the call as ambiguous because although
> the second overload is more constrained than the first, their function
> parameter lists aren't equivalent.

IMHO, `template <C1 T, C2 U> int f(U, T);` should win over `template <C1 T, C1
U> int f(T, U);`.

Based on interpreting the intent mentioned in
https://github.com/cplusplus/nbballot/issues/119 and the second example in
https://eel.is/c++draft/temp.fct#temp.func.order-example-6, the `corresponding`
(of the `corresponding template-parameters of ...`) relationship is based on
the mapping used during partial-ordering deduction. So the deduction between
`f(T, ..)` against `f(U, ..)` builds the <T,U> mapping, the deduction between
`f(.., U)` against `f(.., T)` builds the <U, T> mapping. The correspondence is
[T, U] against [U, T]. So `C1 T` is less constrained than `C2 U`, thus the
second `f` wins.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/99963] [11 Regression] [concepts] template <concept> vs concept auto reports ambiguous overload
  2021-04-07 20:02 [Bug c++/99963] New: [concepts] template <concept> vs concept auto reports ambiguous overload ldalessandro at gmail dot com
                   ` (3 preceding siblings ...)
  2022-06-21 21:21 ` tabloid.adroit at gmail dot com
@ 2022-06-23 18:47 ` tabloid.adroit at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: tabloid.adroit at gmail dot com @ 2022-06-23 18:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99963

--- Comment #5 from Yuanfang Chen <tabloid.adroit at gmail dot com> ---
(In reply to Yuanfang Chen from comment #4)
> (In reply to Patrick Palka from comment #1)
> > Started with r11-1571.  Reduced testcase that replaces the abbreviated
> > function templates with their corresponding non-abbreviated forms:
> > 
> > template <class T> concept C1 = true;
> > template <class T> concept C2 = C1<T> && true;
> > 
> > template <C1 T, C1 U> int f(T, U);
> > template <C1 T, C2 U> int f(U, T);
> > 
> > int x = f(0, 0); // error: ambiguous call
> > 
> > 
> > If I understand the wording of P2113 correctly:
> > 
> >   If deduction against the other template succeeds for both transformed
> > templates, constraints can be considered as follows:
> >   - ... if the corresponding template-parameters of the
> > template-parameter-lists are not equivalent ([temp.over.link]) or if the
> > function parameters that positionally correspond between the two templates
> > are not of the same type, neither template is more specialized than the other
> > 
> > then I think we're correct to reject the call as ambiguous because although
> > the second overload is more constrained than the first, their function
> > parameter lists aren't equivalent.
> 
> IMHO, `template <C1 T, C2 U> int f(U, T);` should win over `template <C1 T,
> C1 U> int f(T, U);`.
> 
> Based on interpreting the intent mentioned in
> https://github.com/cplusplus/nbballot/issues/119 and the second example in
> https://eel.is/c++draft/temp.fct#temp.func.order-example-6, the
> `corresponding` (of the `corresponding template-parameters of ...`)
> relationship is based on the mapping used during partial-ordering deduction.
> So the deduction between `f(T, ..)` against `f(U, ..)` builds the <T,U>
> mapping, the deduction between `f(.., U)` against `f(.., T)` builds the <U,
> T> mapping. The correspondence is [T, U] against [U, T]. So `C1 T` is less
> constrained than `C2 U`, thus the second `f` wins.

Sorry. I spoke too soon. Template parameters reordering is not allowed for the
test case. The call is indeed ambiguous.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-23 18:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 20:02 [Bug c++/99963] New: [concepts] template <concept> vs concept auto reports ambiguous overload ldalessandro at gmail dot com
2021-04-14 15:41 ` [Bug c++/99963] [11 Regression] " ppalka at gcc dot gnu.org
2021-04-14 19:12 ` jason at gcc dot gnu.org
2021-04-15 14:26 ` ldalessandro at gmail dot com
2022-06-21 21:21 ` tabloid.adroit at gmail dot com
2022-06-23 18:47 ` tabloid.adroit at gmail 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).