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

    <tr>
        <th>Summary</th>
        <td>
            clang OpenMP atomic capture compare: Bad diagnostic if overloaded `operator<` is declared (but not used)
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          q-p
      </td>
    </tr>
</table>

<pre>
    The following code, reduced from the [alpaka framework for parallel acceleration](https://github.com/alpaka-group/alpaka) causes an error that -- as far as I can tell -- should not cause one (since the questionable `operator<` should never be used).

Removing the `operator<` overloaded causes the code to compile.

It feels like the diagnostic is emitted too early: Even if the call to `atomicOp` is commented out, then the template should not instantiated and no diagnostic shown, but it still causes a failure.. But I'm not a language lawyer.

```cpp
#define ERROR

#ifdef ERROR
class badouble { };
bool operator < ( double coval, const badouble& v ) ;
#endif

template<class T>
static auto atomicOp(T* const addr, T value) -> T
{
            T old;
            auto& ref(*addr);
// atomically update ref, but capture the original value in old
#        pragma omp atomic capture compare
                {
                    old = ref;
                    // Do not remove the curly brackets of the if body else
                    // icpx 2024.0 is not able to compile the atomics.
                    if(value < ref)
                    {
 ref = value;
                    }
                }
 return old;
}

int main()
{
    int i = 0, j = 1;
 atomicOp(&i, j);
}
```

https://godbolt.org/z/9WsEfEbnG
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8VcGO4jgQ_RpzKYGCAwkccoAGVnNY9aqFtOeKXQZPO3bGdujt_fqVY6CZ6em1kEIc13uvqp5tDEGfLFHDllu23E1wiGfnmx_TftI6-d4czwTKGePetD2BcJIYfwJPchAkQXnXQTwTsOUWTY-vCMpjR2_Ov4JyHnr0aAwZQCHIkMeonWXLHeOrc4x9YOWG8QPjh5OO56GdCdcxfshQ05N3Q39_ZXwNAodAAdACee88xDNGmE4BAyj06fENBFqIZEy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