public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110774] New: Ambiguous partial ordering with non-dependent function parameter type
@ 2023-07-22  1:03 bbi5291 at gmail dot com
  2023-07-22  1:04 ` [Bug c++/110774] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: bbi5291 at gmail dot com @ 2023-07-22  1:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110774
           Summary: Ambiguous partial ordering with non-dependent function
                    parameter type
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bbi5291 at gmail dot com
  Target Milestone: ---

With `g++ -std=c++2b`, the following is rejected:
---
template<typename T>
struct A { typedef char* type; };

template<typename T> char* f1(T, char*);  // #1
template<typename T> long* f1(T*, typename A<T>::type*); // #2

long* p1 = f1(p1, 0); // #3
---
The error message is:
---
<source>:7:14: error: call of overloaded 'f1(long int*&, int)' is ambiguous
    7 | long* p1 = f1(p1, 0); // #3
      |            ~~^~~~~~~
<source>:4:28: note: candidate: 'char* f1(T, char*) [with T = long int*]'
    4 | template<typename T> char* f1(T, char*);  // #1
      |                            ^~
<source>:5:28: note: candidate: 'long int* f1(T*, typename A<T>::type*) [with T
= long int; typename A<T>::type = char*]'
    5 | template<typename T> long* f1(T*, typename A<T>::type*); // #2
      |                            ^~
---

This code is very similar to the code from Core issue 455, but one of the
function parameters has been changed from containing `T` in a non-deduced
context to not containing `T` at all. Since the code from core issue 455 is
supposed to be valid (#2 being chosen) I cannot see any reason why this example
would not also be valid. A non-dependent parameter type should be treated the
same as a parameter type containing the template parameter in a non-deduced
context: in either case, it cannot be used for deduction.

Clang and MSVC also reject this code, but I cannot find any reason why. Is it
possible that all 3 compilers have a bug?

Reflector thread: https://lists.isocpp.org/core/2023/07/14533.php

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

* [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type
  2023-07-22  1:03 [Bug c++/110774] New: Ambiguous partial ordering with non-dependent function parameter type bbi5291 at gmail dot com
@ 2023-07-22  1:04 ` pinskia at gcc dot gnu.org
  2023-07-22  1:07 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-22  1:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The literal 0 is the issue ...

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

* [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type
  2023-07-22  1:03 [Bug c++/110774] New: Ambiguous partial ordering with non-dependent function parameter type bbi5291 at gmail dot com
  2023-07-22  1:04 ` [Bug c++/110774] " pinskia at gcc dot gnu.org
@ 2023-07-22  1:07 ` pinskia at gcc dot gnu.org
  2023-07-22  1:12 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-22  1:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually 0 vs nullptr is the same:
```
template<typename T>
struct A { typedef char* type; };

template<typename T> char* f1(T, char*);  // #1
template<typename T> long* f1(T*, typename A<T>::type*); // #2


long* p1 = f1(p1, nullptr); // #3
```
That is the above also gets ambiguous.

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

* [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type
  2023-07-22  1:03 [Bug c++/110774] New: Ambiguous partial ordering with non-dependent function parameter type bbi5291 at gmail dot com
  2023-07-22  1:04 ` [Bug c++/110774] " pinskia at gcc dot gnu.org
  2023-07-22  1:07 ` pinskia at gcc dot gnu.org
@ 2023-07-22  1:12 ` pinskia at gcc dot gnu.org
  2023-07-22  1:15 ` [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type and nullptr pinskia at gcc dot gnu.org
  2023-07-22  1:17 ` bbi5291 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-22  1:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Take:
```
template<typename T>
struct A { typedef char* type; };

template<typename T> char* f1(T, char*);  // #1
template<typename T> long* f1(T*, typename A<T>::type*); // #2

char *t;
char **t1;
long* p0;
long *p1 = f1(p0, t1); // choses #2
char* p2 = f1(p0, t); // choses #1
```
GCC, MSVC, and clang all compile the above.

So is it only an issue with nullptr where it could chose either?

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

* [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type and nullptr
  2023-07-22  1:03 [Bug c++/110774] New: Ambiguous partial ordering with non-dependent function parameter type bbi5291 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-07-22  1:12 ` pinskia at gcc dot gnu.org
@ 2023-07-22  1:15 ` pinskia at gcc dot gnu.org
  2023-07-22  1:17 ` bbi5291 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-22  1:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
But these function declarations are not partial specializations as far as I
know.

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

* [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type and nullptr
  2023-07-22  1:03 [Bug c++/110774] New: Ambiguous partial ordering with non-dependent function parameter type bbi5291 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-07-22  1:15 ` [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type and nullptr pinskia at gcc dot gnu.org
@ 2023-07-22  1:17 ` bbi5291 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: bbi5291 at gmail dot com @ 2023-07-22  1:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Brian Bi <bbi5291 at gmail dot com> ---
Partial ordering is different from partial specialization. Partial ordering
selects a best viable function in certain cases where two viable functions are
both instantiated from templates.

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

end of thread, other threads:[~2023-07-22  1:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-22  1:03 [Bug c++/110774] New: Ambiguous partial ordering with non-dependent function parameter type bbi5291 at gmail dot com
2023-07-22  1:04 ` [Bug c++/110774] " pinskia at gcc dot gnu.org
2023-07-22  1:07 ` pinskia at gcc dot gnu.org
2023-07-22  1:12 ` pinskia at gcc dot gnu.org
2023-07-22  1:15 ` [Bug c++/110774] Ambiguous partial ordering with non-dependent function parameter type and nullptr pinskia at gcc dot gnu.org
2023-07-22  1:17 ` bbi5291 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).