[PATCH] D24372: [libcxx] Sprinkle constexpr over compressed_pair

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 9 11:49:00 PDT 2016

rsmith added a subscriber: rsmith.

Comment at: test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/constinit.pass.cpp:19-23
@@ +18,6 @@
+_LIBCPP_SAFE_STATIC static std::unique_ptr<int> a;
+int main() {
+    assert(a == nullptr);
This is a bit painful to test without _LIBCPP_SAFE_STATIC, because the contents of `a` will be all 0 bits on program startup regardless of whether static or dynamic initialization is performed. Something like this might work though:

  extern std::unique_ptr<int> a;
  void *trample = std::memset(&a, 0xab, sizeof(a));
  _LIBCPP_SAFE_STATIC std::unique_ptr<int> a;

  int main() {
    // Check that the initialization of 'a' was performed before the initialization of 'trample'.
    for (size_t n = 0; n != sizeof(a); ++n)
      assert(reinterpret_cast<char*>(trample)[n] == 0xab);
    // Put a unique_ptr object back so that the global dtor is valid.
    new (&a) std::unique_ptr<int>;



More information about the cfe-commits mailing list