Issue 76837
Summary Cannot directly call conversion operator in SFINAE context
Labels
Assignees
Reporter gracicot
    Clang seem to not expand the template parameter when directly calling a conversion operator in SFINAE context.

Reproduction:

```c++
struct a {
    operator int();
};

template<typename A>
struct b {
 template<typename B, decltype(void(A{}.operator B()))* = nullptr>
 auto func() {}
};

int main() {
 b<a>{}.func<int>();
}
```

GCC and clang compile this code correctly, clang fails with:
```
<source>:7:40: error: no member named 'operator type-parameter-0-0' in 'a'
    7 | template<typename B, decltype(void(A{}.operator B()))* = nullptr>
      | ~~~ ^
<source>:12:5: note: in instantiation of template class 'b<a>' requested here
   12 |     b<a>{}.func<int>();
      | ^
<source>:12:12: error: no member named 'func' in 'b<a>'
   12 | b<a>{}.func<int>();
      |     ~~~~~~ ^
<source>:12:20: error: expected '(' for function-style cast or type construction
   12 | b<a>{}.func<int>();
      |                 ~~~^
<source>:12:22: error: expected _expression_
   12 |     b<a>{}.func<int>();
      | ^
4 errors generated.
```

Compiler explorer link: https://godbolt.org/z/6on57GehY 

This seems to only happen when the template parameter is not immediate context. Defining `struct b` as follows will make clang accept the code:
```
struct a {
    operator int();
};

struct b {
    template<typename A, typename B, decltype(void(A{}.operator B()))* = nullptr>
    auto func() {}
};

int main() {
    b{}.func<a, int>();
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to