6 # [...] Similarly, the evaluation of a call to std​::​construct_­at or std​::​ranges​::​construct_­at ([specialized.construct]) does not disqualify E from being a core constant expression unless the first argument, of type T*, does not point to storage allocated with std​::​allocator or to an object whose lifetime began within the evaluation of E, or the evaluation of the underlying constructor call disqualifies E from being a core constant expression.

According to the wording, this code should be ill-formed, but implementations accept it: https://compiler-explorer.com/z/f8Tjx8EK5.

#include <memory>
union num {
  int i;
  constexpr num() {
    std::construct_at(&i); // the first argument does not point
    // to storage allocated with std​::​allocator<T> or
    // to an object whose lifetime began within the evaluation of E
  }
};
static_assert(num{}.i == 0);
0
© 2022 pullanswer.com - All rights reserved.