<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94594>94594</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang can't compare 2 pointers into the same multidimensional array at compile time
</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>
Take this example:
```c++
struct A {};
constexpr A a[3][3];
constexpr int diff2 = &a[1][3] - &a[0][0];
```
clang prints:
```console
<source>:7:15: error: constexpr variable 'diff2' must be initialized by a constant expression
7 | constexpr int diff2 = &a[1][3] - &a[0][0];
| ^ ~~~~~~~~~~~~~~~~~~~
<source>:7:32: note: subtracted pointers are not elements of the same array
7 | constexpr int diff2 = &a[1][3] - &a[0][0];
|
```
but all other compilers seem to accept this code just fine: https://godbolt.org/z/f7bGEThTT
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8U8uO6zYM_Rp6Q8zAkR-KF17kMekP5AckmY51K0uGRA_u3EW_vZAzubntoF0VJYQoODKpc3golZK9eaIemiM050KtPIXYs1Y0UIyFDsNHf1W_E_JkE9J3NS-OoDpAeYby8duW92VAHPPa0MRxNYwHBHkEeYbqEzfBJ6bvS8QDKmiOFTTnx_b1G-sZBzuOAqE6I4g2p-yeKfjyAMs7WP5a5yezX-kap_wNl2g9p6eSnxqCT8HRJ1qdUlijIajeoDpIqA67BqoDUowh5j9Ppu8qWqUdIQi5MQYhcV4Toya03rJVzv6gAfUHqnue8ow5l1Kywd-vRESUCPKE_1UTcItc8a8BzRv-8TX-UXklsmAfOPuPadUclWEacAnWM8WEKlI-R3I0k-eEYUSeCJOaCVWM6uN_0_gv_uuVUTmHgSeKaMK8WJfZJ6IZOaAyhha-D7wJA-G3bOJo_aZ7Yl62sREXEJdbGHRw_BriDcTlB4jLKPVvb9fpei2Gvhq6qlMF9Tu5k23b1DtZTL2ksjO1rsV-rEa9FyQb2u90KeVQGmpNYXtRirpsy7bsdm0jX01lxnq_12NtTKe7FuqSZmXdq3Pvc767sCmt1Hd109WFU5pc2l60ENuwQ3UYY_BMfgAhQJzywaPzGWnORexzsRe93hLUpbOJ07M8W3bUn7aHY5QHIXlrXDZcPP23nsPT8Hl1bAc7k8_Trdx9AlDxo-fIdqZija7_W1MtT6t-NWEGcckcPreXJYZvZBjEZdObQFzukt978WcAAAD__6dtazA">