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

Reply via email to