[libcxx-commits] [PATCH] D116346: [libc++] Fix __wrap_iter copy-assignment in constexpr contexts

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 2 08:27:42 PST 2022


philnik updated this revision to Diff 396931.
philnik added a comment.

- Use feature test macro


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116346/new/

https://reviews.llvm.org/D116346

Files:
  libcxx/include/__iterator/wrap_iter.h
  libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp


Index: libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
===================================================================
--- libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
+++ libcxx/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
@@ -23,12 +23,13 @@
 #include "test_macros.h"
 
 template<class C>
-void test()
+TEST_CONSTEXPR_CXX20 void test()
 {
     { // N3644 testing
         typename C::iterator ii1{}, ii2{};
         typename C::iterator ii4 = ii1;
         typename C::const_iterator cii{};
+
         assert ( ii1 == ii2 );
         assert ( ii1 == ii4 );
 
@@ -49,10 +50,17 @@
         assert (cii - ii1 == 0);
         assert (ii1 - cii == 0);
     }
+    {
+        C a;
+        typename C::iterator i1 = a.begin();
+        typename C::iterator i2;
+        assert ( i1 != i2 );
+        i2 = i1;
+        assert ( i1 == i2 );
+    }
 }
 
-int main(int, char**)
-{
+TEST_CONSTEXPR_CXX20 bool test() {
     test<std::string>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test<std::wstring>();
@@ -65,5 +73,14 @@
     test<std::u16string>();
     test<std::u32string>();
 
+    return true;
+}
+
+int main(int, char**)
+{
+    test();
+#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
+    static_assert(test());
+#endif
     return 0;
 }
Index: libcxx/include/__iterator/wrap_iter.h
===================================================================
--- libcxx/include/__iterator/wrap_iter.h
+++ libcxx/include/__iterator/wrap_iter.h
@@ -69,9 +69,10 @@
     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
     __wrap_iter& operator=(const __wrap_iter& __x)
     {
-        if (this != _VSTD::addressof(__x) && !__libcpp_is_constant_evaluated())
+        if (this != _VSTD::addressof(__x))
         {
-            __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
+            if (!__libcpp_is_constant_evaluated())
+                __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
             __i = __x.__i;
         }
         return *this;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116346.396931.patch
Type: text/x-patch
Size: 2082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220102/adc34639/attachment.bin>


More information about the libcxx-commits mailing list