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

    <tr>
        <th>Summary</th>
        <td>
            [Clang][concepts] Clang may fail to match the appropriate partial specialization if contrained by a requires expression containing lambdas
        </td>
    </tr>

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

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

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

<pre>
    This issue is first found on clangd 17 shipped with CLion 2023.1.2 (https://github.com/llvm/llvm-project/commit/22d98280dd8ee70064899eefb973a1c020605874), and reproduced on x86_64 clang trunk on compiler explorer (https://github.com/llvm/llvm-project/commit/0a02f76d11d727ca89a1cd3d29e0b867de7051d9) and clang-17 from apt.llvm.org (https://github.com/llvm/llvm-project/commit/6875424135312aeb26ab8e0358ba7f9e6e80e74).

This issue seems to only occur when:

1. There's a class template (`template <class T> struct A`).
2. There's a constrained partial specialization (`template <C T> struct A<T>`).
3. That is effectively contrained by a `requires` expression (`template <class T> concept C = requires ...;`).
4. That `requires` expression contains a lambda expression.
5. That contraint is not tested before.

Given a type `T` which satisfies that constraint (i.e. `static_assert(C<T>)`), clang trunk will fail to match the partial specialization `template <C T> struct A<T>` if the constraint is not explicitly tested before (including `static_assert(C<T>)`), and any test to the constraint will fail afterwards.

MRE#1: https://godbolt.org/z/rEfP7PcPc, lambda used as a simple requirement. 
MRE#2: https://godbolt.org/z/GhqdnqMGb, lambda used inside parameter list with `decltype`.

A slightly longer but more meaningful example: https://godbolt.org/z/xfGjrq7db.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVV1P4zoT_jXuzWgjx_lyLnoBhXLzroRecb9y7EnjPY4dbIfS_fVHTtulhUXiaG-A0PT5mHlmRoSgdxZxTapbUt2txBwH59fotRVSu1Xn1GH9NOgAOoQZQQfotQ8RejdbBc6CNMLu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