Issue |
117294
|
Summary |
[Clang] Placement-new in constant evaluation can give indeterminate result
|
Labels |
c++20,
clang:frontend,
c++26,
constexpr
|
Assignees |
|
Reporter |
frederick-vs-ja
|
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`).
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs