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

    <tr>
        <th>Summary</th>
        <td>
            Pointer-to-integral casts are diagnosed differently when in a binary operator
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            constexpr
      </td>
    </tr>

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

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

<pre>
    See: https://godbolt.org/z/ovqcs949s

```c++
int a[12];

static_assert( ((__UINTPTR_TYPE__)&a[7]));

static_assert( ((__UINTPTR_TYPE__)&a[7]) == 0);
```

The output is:
```console
<source>:9:16: error: static assertion expression is not an integral constant expression
    9 | static_assert( ((__UINTPTR_TYPE__)&a[7]));
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
<source>:9:17: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
 9 | static_assert( ((__UINTPTR_TYPE__)&a[7]));
      | ^~~~~~~~~~~~~~~~~~~~~~~
<source>:11:42: error: static assertion expression is not an integral constant expression
   11 | static_assert( ((__UINTPTR_TYPE__)&a[7]) == 0);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
```

It seems inconsistent to me to diagnose the second example differently (or worse) than the first one, just because it's the subexpression of a binary operator.

This is happening because:
https://github.com/llvm/llvm-project/blob/6de5305b3d7a4a19a29b35d481a8090e2a6d3a7e/clang/lib/AST/ExprConstant.cpp#L13874-L13876

Doing a `return false` here instead of the `Error(E)` makes the previous diagnostic show up and the two cases are diagnosed the same.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8lU1v4zYTxz_N-DKIIZGyXg46OLENLPDgQdBNDz0ZI2lscSuTKjnKSw_57AXlZOMNNgsU3VYQ9EKJo_n95z8UhWCOlrmG1TWsNguapHe-loa4Y-8Xjeue6s_MoNfYi4wB9BrUDtTu6LrG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