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

            Bug ID: 107507
           Summary: Conversion function templates are not sometimes not
                    considered if the return type is type dependent
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dangelog at gmail dot com
  Target Milestone: ---

Testcase:

template <typename T>
struct Test {
    template <typename = void>
    operator T();
};

int main() {
    Test<int *> t;

    int *x = t; // OK
    int *y = t + 42; // ERROR
}



<source>: In function 'int main()':
<source>:20:16: error: no match for 'operator+' (operand types are 'Test<int*>'
and 'int')
  228 |     int *y = t + 42;
      |              ~ ^ ~~
      |              |   |
      |              |   int
      |              Test<int*>




This seems to depend on whether the conversion operators themselves are
function templates that return a type dependend on T. For instance, this works:


template <typename T>
struct Test {
    template <typename = void>
    operator int *(); // don't return a type that depends on T
};

int main() {
    Test<int *> t;

    int *x = t; 
    int *y = t + 42; // OK
}



And also this works:



template <typename T>
struct Test {
    operator T(); // not a template
};

int main() {
    Test<int *> t;

    int *x = t;
    int *y = t + 42;
}



I see that conversion function templates are treated in a special way in a
couple of places in the Standard but I'm not sure -- e.g. does
https://eel.is/c++draft/over.ics.user#3 apply here?. For comparison, Clang also
rejects this, while MSVC (in C++latest mode) accepts it.

Reply via email to