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

    <tr>
        <th>Summary</th>
        <td>
            [clang] __has_unique_object_representations gives inconsistent answer based on instantiation order
        </td>
    </tr>

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

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

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

<pre>
    The following code reports inconsistent results for `__has_unique_object_representations`:

```c++
template <int>
class Foo {
  int x;
};

static_assert(__has_unique_object_representations(Foo<0>[]));
static_assert(__has_unique_object_representations(Foo<0>[][3]));
static_assert(__has_unique_object_representations(Foo<0>));
```

The key here is that if you assert `__has_unique_object_representations(Foo<0>)` **first**, then everything works. So somehow asking for `__has_unique_object_representations(Foo<0>)` must cause something to be instantiated or stored in the AST and that changes the result of a subsequent `__has_unique_object_representations(Foo<0>[])` query (notice the array).

This bug was extracted from this comment: https://github.com/llvm/llvm-project/pull/69241#issuecomment-2163612863

Godbolt: https://gcc.godbolt.org/z/Pb9ze7YxM
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VE2PnDgQ_TXmUkrLmAaaA4fOzLKnlVZKLntqGVOAd9yuHpeZns6vXxlmkkmUw2S1K5WMccF79fFcmtlOHrEV5UdR3md6iTOF1g2WvMesp-HWfp4RRnKOrtZPYGhACHihEBmsN-TZckQfISAvLjKMFEBU8nSaNZ8Wbx8XPFH_N5p4CngJyOijjpY8i0qK4ijkvZCvayU3M0J9TLaeRjxfnI4IorizPorit-3cOM0MHRGI-uVTAOsjPIvi5V3U99_268qJ3Jw0M4Yo1OE9capDRySKO5mo10oJ1SR7hf6PQMuPxf-A_T3c1xK_LUrq8QPeYMaAYBnirCPYEW60wEb83pb-yFxJEOoo1HG0geO2FeoO4owe8AnDLc5JV1cKD7yDTwRMZ5zpCpofkuMX5PQT7vPCEYxeGFfcjSsS9AjWc9Q-Wh1xAArAkQIOYH2KDY6fPoP2w1YJM2s_Ia-OTeZAI2jgpWd8XJL6_02IX5VUSXhcMNxAqIOnaA2uVDoEfROq2X3fKsvQLxNcNQM-x6BNSmAMdIaYfIbOZ0y35AhzjBdOV0x1QnWTjfPS7wydheqce3p9fLgESsEK1V0W54Tqqkbtc6EKy7zgC94HlVdFlatDVbwN53caenI_YzNmN23OHYVJqO6LUN2fffMF67-e_8iGthiaotEZtnmdH5SqZVVmc1vtZW5GLfu-zOviMObNWA-lLA6lHPRY15ltlVR7WeVK5Xm9L3fDYWjU3hSyzMtejY3YSzxr63YpucSdrXm0TVnkeeZ0j47XgaeUcdpPQqk0-0K7FqNfJhZ76SxH_oYQbXTrlNz-KO_hHd2GyT7hD1NSe75igF5zUp1_o0JLHigMGLIluPaXW7fmyEJ1W5pPrfonAAD__3Vn6SE">