<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/76837>76837</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Cannot directly call conversion operator in SFINAE context
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          gracicot
      </td>
    </tr>
</table>

<pre>
    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>();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vs2SqzYTfRp502UXSLZhFiwYPL71bb5Fkk2WQjRGuUIikpifLPzsqQaP7ZnyTN0kk6go7ALRfbr79GnJEPTBIhZsc882u4UcY-d8cfBSaeXionbNS1EZaQ8QEHuIDqyLgM-Dt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