<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153989>153989</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
en.cppreference.com/w/cpp/memory/construct_at does not compile
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cppljevans
</td>
</tr>
</table>
<pre>
clang-20 doesn't compile when defined(USE_CONST_EVAL) in the following example:
````
//Purpose:
// Test:
/*
https://en.cppreference.com/w/cpp/memory/construct_at
*/
//===========
#include <iostream>
#include <memory>
struct
S
{
int x;
float y;
double z;
public:
constexpr S( int _x, float _y, double _z)
: x(_x)
, y(_y)
, z(_z)
{}
[[nodiscard("no side-effects!")]]
constexpr bool operator==(const S&) const noexcept = default;
};//S struct
//#define USE_CONST_EVAL
#ifdef USE_CONST_EVAL
consteval
#else
constexpr
#endif
bool test()
{
alignas(S) unsigned char storage[sizeof(S)]{};
S uninitialized = std::bit_cast<S>(storage);
std::destroy_at(&uninitialized);
S* ptr = std::construct_at(std::addressof(uninitialized), 42, 2.71f, 3.14);
const bool res{*ptr == S{42, 2.71f, 3.14}};
std::destroy_at(ptr);
return res;
}
int main()
{
bool const result=test();
std::cout<<":result="<<result<<";\n";
return 0;
}
//=======
//Result:
/*
#ifdef USE_CONST_EVAL
make -k --always-make run
/usr/lib/llvm-20/bin/clang++ -c -std=c++2c -stdlib=libc++ -isystem /usr/lib/llvm-20/include/c++/v1 -ftemplate-backtrace-limit=0 -g -c construct_at.constexpr.cpp -MMD -o build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.o
construct_at.constexpr.cpp:45:23: error: call to consteval function 'test' is not a constant expression
45 | bool const result=test();
| ^
construct_at.constexpr.cpp:36:7: note: destroying object 'uninitialized' whose lifetime has already ended
36 | S uninitialized = std::bit_cast<S>(storage);
| ^
construct_at.constexpr.cpp:45:23: note: in call to 'test()'
45 | bool const result=test();
| ^~~~~~
1 error generated.
make: *** [/home/larry/prog_dev/Makefile.incs/MAIN.imk:10: build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.o] Error 1
make: Target 'run' not remade because of errors.
Compilation exited abnormally with code 2 at Sat Aug 16 20:22:47, duration 0.48 s
#else
make -k --always-make run
/usr/lib/llvm-20/bin/clang++ -c -std=c++2c -stdlib=libc++ -isystem /usr/lib/llvm-20/include/c++/v1 -ftemplate-backtrace-limit=0 -g -c construct_at.constexpr.cpp -MMD -o build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.o
sed -e 's#^construct_at.constexpr.o:#build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.o:#' ./build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.d > build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.o.dep
rm ./build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.d
install -d build/boost-1_85_0/clangxx-20-2c
/usr/lib/llvm-20/bin/clang++ -L/usr/lib/llvm-20/lib -Wl,-rpath,/usr/lib/llvm-20/lib -lc++ -lc++abi -v -fuse-ld=lld build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.o -o build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.exe
Ubuntu clang version 20.1.8 (++20250804090239+87f0227cb601-1~exp1~20250804210352.139)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-20/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/14
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/usr/lib/llvm-20/bin/ld.lld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.exe /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/14/crtbeginS.o -L/usr/lib/llvm-20/lib -L/usr/lib/gcc/x86_64-linux-gnu/14 -L/usr/lib/gcc/x86_64-linux-gnu/14/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/lib/llvm-20/bin/../lib -L/lib -L/usr/lib -rpath /usr/lib/llvm-20/lib -lc++ -lc++abi build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/14/crtendS.o /lib/x86_64-linux-gnu/crtn.o
./build/boost-1_85_0/clangxx-20-2c/construct_at.constexpr.exe
:result=1;
Compilation finished at Sat Aug 16 20:27:34, duration 0.50 s
#endif//USE_CONST_EVAL
*/
````
I downloaded llvm-20 from synatic. My system is revealed by:
````
larry@larry-Precision-3581:~/prog_dev/Makefile.incs$ uname -a
Linux larry-Precision-3581 6.5.0-1027-oem #28-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 25 13:32:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
````
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUGV1v4jr217gvR44ShxB44IFCuZrV7ezo0tnVPiEnOQHfcezIdlrow_z2lZ1AC-10ZrZ9WRRBcnx8vr8cuLViqxBnJLsm2fKKd26nzaxsW_k33nNlrwpdHWal5GpLWQyVRqsIyx2UummFRHjYoYIKa6GwImzydX2zWfzz8_puc_Ov-Z-ETUEocDuEWkupH4TaAu5500ok6ZzEczKOn654TtiKsNWXzrTaHjECCO7QumcAf7NzrrUeFjBQRWXbGqzRoCoxKnVD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