Make __builtin_launder test code C++03.

This commit is contained in:
jzmaddock
2026-07-11 11:29:33 +01:00
parent 6a9a25dd6e
commit da4d0375f0
+7 -4
View File
@@ -12,18 +12,21 @@
#include <new>
namespace boost_has_builtin_launder {
//
// This is intensionally C++03 code as __builtin_launder can be used even when std::launder
// isn't available (ie pre-C++17).
struct X
{
const int const_int;
X() = delete;
X() : const_int(0) {};
X(const int i) : const_int(i) {}
X(const X& o) : const_int(o.const_int) {};
};
int test()
{
X original{1};
new (&original) X{2}; //Overwrite X
X original(1);
new (&original) X(2); //Overwrite X
return __builtin_launder(&original)->const_int == 2 ? 0 : -1; //After laundering, new value should be returned
}