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

    <tr>
        <th>Summary</th>
        <td>
            Clang rejects out-of-line implementation as not matching with templated self type in concept
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Clang is unable to match an out-of-line definition to the declaration if it passes its own type to a concept, and its own type is a template.

Removing the template on the struct `S` makes the error go away. There is no work around other than writing the function definition in line, as far as I can tell. This reproduces in Clang 16.

Godbolt: https://godbolt.org/z/nG1v5e9re

```cpp
template <class A, class B>
concept C = true;

template <class T>
struct S {
    template <C<S<T>> I>
    S f();

    template <class I>
 requires C<I, S<T>>
    S f2();
};

template <class T>
template <C<S<T>> I>
S<T> S<T>::f() {  // out-of-line definition of 'f' does not match any declaration
    return S();
}

template <class T>
template <class I>
    requires C<I, S<T>>
S<T> S<T>::f2() {   // Clang: out-of-line definition of 'f2' does not match any declaration
    return S();
}

int main() {}`
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVE2P4jgQ_TWVS6lRYkNCDjnQ9DDq6zJ_wHEqxNOOnbWdRuyvXzkBOs3s7JdGQhiVq-rVe7ie8F6dDFEFm2fYvCRiDJ11VSOMePue1La5VHstzAmVx9GIWhMGi70IskNh0I7hybZPWhnChlplVFDWxJTQxYjUwokppFpUAQfhPXlUwaM9GwyXYeonUFojaQjA9ihM8zlBeRQYqB-0CLSC9AXS3fz9G_X2XZnThHbLwDhAR-iDG2VAyNMj5Cn24o38dEHOWYcni-IsLiv81pGbQIzFs3VvKJwdTYM2dOQwdMLg2alwg2lHIydGC77KYJRgmt5jK1w8XlEKg4G0jhjKo6PB2WaUUQCDs6xZ_onQV9vUVgfgO-xCGDzwHbADsMNpvlhZdwJ2-APYwXzN3jdUOlrWQ57OHzkMc-SuCvC91MJ73MUx55_PwL_MaVf9cY_AXzC4kYA_Lzv_2Ofbvfiq9BGhuNYgIi4r9sD3R-D7qYZ_wdd7bcw8YgtsC6x8wHzsMuMuah39PipHHmP_18hrAfKpP3sEKF7-A8F_R-UWXQyxA767coviIM7_5s_2xrYIrGiBFdhYii8y3HftslynD26OwugMHv-C3_8g94PCE8I_ivwz5mxJ_cZ9evjxhf-9COzXq6BMbKTMx1QxIU8fdidpKt6UvBQJVVm-3ZY52xZp0lVrlsl2zWUj19kmK4g227KWueR5VqdlLRJVsZTxtMjSdM2ydLta5-VWFHVDeb7OOeWwTqkXSq-0fu_jMifK-5GqnBd5mWhRk_aTFTNm6IzTJTAWndlVseapHk8e1qlWPviPLkEFTVendvSdZPTPhbyqHzT1ZMJsxmIhavS1swrdfdMa9KTbq_WamzMno9PVgyep0I31Stoe2CGOcj2eBmfjCMAOEwEP7DAR_DMAAP__xWrubw">