[libcxx-commits] [libcxx] 0da95a5 - [libc++] Workaround non-constexpr std::exchange pre C++20

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 13 07:51:21 PDT 2021


Author: Louis Dionne
Date: 2021-07-13T10:51:03-04:00
New Revision: 0da95a5cf2691c8e01ae02f108487c397ab7e0ce

URL: https://github.com/llvm/llvm-project/commit/0da95a5cf2691c8e01ae02f108487c397ab7e0ce
DIFF: https://github.com/llvm/llvm-project/commit/0da95a5cf2691c8e01ae02f108487c397ab7e0ce.diff

LOG: [libc++] Workaround non-constexpr std::exchange pre C++20

std::exchange is only constexpr in C++20 and later. We were using it
in a constructor marked unconditionally constexpr, which caused issues
when building with -std=c++17.

The weird part is that the issue only showed up when building on the
arm64 macs, but that must be caused by the specific version of Clang
used on those. Since the code is clearly wrong and the fix is obvious,
I'm not going to investigate this further.

Added: 
    

Modified: 
    libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/explicit_optional_U.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/explicit_optional_U.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/explicit_optional_U.pass.cpp
index a591b5f62e69b..708370a47b616 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/explicit_optional_U.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/explicit_optional_U.pass.cpp
@@ -48,7 +48,7 @@ class X
     int i_;
 public:
     constexpr explicit X(int i) : i_(i) {}
-    constexpr X(X&& x) : i_(std::exchange(x.i_, 0)) {}
+    constexpr X(X&& x) : i_(x.i_) { x.i_ = 0; }
     TEST_CONSTEXPR_CXX20 ~X() {i_ = 0;}
     friend constexpr bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
 };


        


More information about the libcxx-commits mailing list