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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Placement-new in constant evaluation can give indeterminate result
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            clang:frontend,
            c++26,
            constexpr
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          frederick-vs-ja
      </td>
    </tr>
</table>

<pre>
    The following program shouldn't be accepted per [[expr.const]/5.18.2.1](https://eel.is/c++draft/expr.const#5.18.2.1) as corrected by [CWG2922](https://cplusplus.github.io/CWG/issues/2922.html) (since the constructed array type is unsuitable).

However, Clang currently accepts it and give different results in different compilation. [Godbolt link](https://godbolt.org/z/asjev19vj).

```C++
#include <new>
#include <typeinfo>

constexpr int N = []
{
    struct S {
        int a[1];
    };
    S s;
    ::new (s.a) int[1][2][3][4]();
    return s.a[0];
}();

template<int X>
struct tag {};

void unknown(const std::type_info&) noexcept;

int main()
{
 unknown(typeid(tag<N>));
}
```

Moreover, the following seems valid because the array type is suitable, but there are still indeterminate results. [Godbolt link](https://godbolt.org/z/5bPfns185).
(The correct `N` is `0`.)

```C++
#include <new>
#include <typeinfo>

constexpr int N = []
{
    struct S {
        int a[1];
    };
    S s;
    ::new (s.a) int[1](); // s.a is converted to the poiner to s.a[0]
    return s.a[0];
}();

template<int X>
struct tag {};

void unknown(const std::type_info&) noexcept;

int main()
{
 unknown(typeid(tag<N>));
}
```

This can be also trigged by the current resolution of [LWG3436](https://cplusplus.github.io/LWG/issue3436) (so labled `c++20`).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVs1u4zYQfhr6MoggjX5sHXyI7To9bBcLbID0VlDiSGZCkwJJKZs-fUFKWdtBgBa9toZNWRxyfr6Zj0PunOw10ZaVO1YeVnz0J2O3nSVBVrYvd5O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