[libcxx] r273831 - Fix PR28079 - std::wstring_convert move constructor broken.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 26 15:56:26 PDT 2016


Author: ericwf
Date: Sun Jun 26 17:56:26 2016
New Revision: 273831

URL: http://llvm.org/viewvc/llvm-project?rev=273831&view=rev
Log:
Fix PR28079 - std::wstring_convert move constructor broken.

The move constructor for wstring_convert accidentally copied the state member
into the converted count member in the move constructor. This patch fixes
the typo.

While working on this I discovered that wstring_convert doesn't actually
provide a move constructor according to the standard and therefore this
constructor is a libc++ extension. I'll look further into whether libc++ should
provide this constructor at all. Neither libstdc++ or MSVC's STL provide it.

Added:
    libcxx/trunk/test/libcxx/localization/locales/locale.convenience/
    libcxx/trunk/test/libcxx/localization/locales/locale.convenience/conversions/
    libcxx/trunk/test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/
    libcxx/trunk/test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/ctor_move.pass.cpp
    libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_copy.pass.cpp
Modified:
    libcxx/trunk/include/locale

Modified: libcxx/trunk/include/locale
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=273831&r1=273830&r2=273831&view=diff
==============================================================================
--- libcxx/trunk/include/locale (original)
+++ libcxx/trunk/include/locale Sun Jun 26 17:56:26 2016
@@ -3634,7 +3634,7 @@ wstring_convert<_Codecvt, _Elem, _Wide_a
         : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)),
           __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)),
           __cvtptr_(__wc.__cvtptr_),
-          __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtstate_)
+          __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtcount_)
 {
     __wc.__cvtptr_ = nullptr;
 }

Added: libcxx/trunk/test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/ctor_move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/ctor_move.pass.cpp?rev=273831&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/ctor_move.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/ctor_move.pass.cpp Sun Jun 26 17:56:26 2016
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// wstring_convert(wstring_convert&& other); // EXTENSION
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+    typedef std::codecvt_utf8<wchar_t> Codecvt;
+    typedef std::wstring_convert<Codecvt> Myconv;
+    // create a converter and perform some conversions to generate some
+    // interesting state.
+    Myconv myconv;
+    myconv.from_bytes("\xF1\x80\x80\x83");
+    const int old_converted = myconv.converted();
+    assert(myconv.converted() == 4);
+    // move construct a new converter and make sure the state is the same.
+    Myconv myconv2(std::move(myconv));
+    assert(myconv2.converted() == 4);
+}

Added: libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_copy.pass.cpp?rev=273831&view=auto
==============================================================================
--- libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_copy.pass.cpp (added)
+++ libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_copy.pass.cpp Sun Jun 26 17:56:26 2016
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// wstring_convert(wstring_convert const&) = delete;
+// wstring_convert& operator=(wstring_convert const&) = delete;
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+    typedef std::codecvt_utf8<wchar_t> Codecvt;
+    typedef std::wstring_convert<Codecvt> Myconv;
+    static_assert(!std::is_copy_constructible<Myconv>::value, "");
+    static_assert(!std::is_copy_assignable<Myconv>::value, "");
+}




More information about the cfe-commits mailing list