[libcxx-commits] [libcxx] [libc++][sstream] Add deleted special member functions (PR #80254)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 1 04:46:25 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Hristo Hristov (H-G-Hristov)

<details>
<summary>Changes</summary>

The standard declares the copy constructors and copy assign operators as deleted.

References:
- https://eel.is/c++draft/string.streams

---
Full diff: https://github.com/llvm/llvm-project/pull/80254.diff


9 Files Affected:

- (modified) libcxx/include/sstream (+16) 
- (added) libcxx/test/std/input.output/string.streams/istringstream/istringstream.assign/copy.compile.pass.cpp (+25) 
- (added) libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/copy.compile.pass.cpp (+25) 
- (added) libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.assign/copy.compile.pass.cpp (+25) 
- (added) libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/copy.compile.pass.cpp (+25) 
- (added) libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/copy.compile.pass.cpp (+27) 
- (added) libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/copy.compile.pass.cpp (+27) 
- (added) libcxx/test/std/input.output/string.streams/stringstream/stringstream.assign/copy.compile.pass.cpp (+25) 
- (added) libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/copy.compile.pass.cpp (+25) 


``````````diff
diff --git a/libcxx/include/sstream b/libcxx/include/sstream
index 6c354cf0b3973..2a009b05b2ba6 100644
--- a/libcxx/include/sstream
+++ b/libcxx/include/sstream
@@ -48,10 +48,12 @@ public:
     template <class SAlloc>
     explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s,
                              ios_base::openmode which = ios_base::in | ios_base::out); // C++20
+    basic_istringstream(const basic_istringstream&) = delete;
     basic_stringbuf(basic_stringbuf&& rhs);
     basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a);                   // C++20
 
     // [stringbuf.assign] Assign and swap:
+    basic_istringstream& operator=(const basic_istringstream&) = delete;
     basic_stringbuf& operator=(basic_stringbuf&& rhs);
     void swap(basic_stringbuf& rhs) noexcept(see below);                               // conditionally noexcept since C++20
 
@@ -119,9 +121,11 @@ public:
     template <class SAlloc>
     explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s,
                                  ios_base::openmode which = ios_base::in);             // C++20
+    basic_istringstream(const basic_istringstream&) = delete;
     basic_istringstream(basic_istringstream&& rhs);
 
     // [istringstream.assign] Assign and swap:
+    basic_istringstream& operator=(const basic_istringstream&) = delete;
     basic_istringstream& operator=(basic_istringstream&& rhs);
     void swap(basic_istringstream& rhs);
 
@@ -178,9 +182,11 @@ public:
     template <class SAlloc>
     explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s,
                                  ios_base::openmode which = ios_base::out);            // C++20
+    basic_ostringstream(const basic_ostringstream&) = delete;                             
     basic_ostringstream(basic_ostringstream&& rhs);
 
     // [ostringstream.assign] Assign and swap:
+    basic_ostringstream& operator=(const basic_ostringstream&) = delete;
     basic_ostringstream& operator=(basic_ostringstream&& rhs);
     void swap(basic_ostringstream& rhs);
 
@@ -237,9 +243,11 @@ public:
     template <class SAlloc>
     explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
                                 ios_base::openmode which = ios_base::out | ios_base::in); // C++20
+    basic_stringstream(const basic_stringstream&) = delete;
     basic_stringstream(basic_stringstream&& rhs);
 
     // [stringstream.assign] Assign and swap:
+    basic_stringstream& operator=(const basic_stringstream&) = delete;
     basic_stringstream& operator=(basic_stringstream&& rhs);
     void swap(basic_stringstream& rhs);
 
@@ -364,6 +372,7 @@ public:
   }
 #endif // _LIBCPP_STD_VER >= 20
 
+  basic_stringbuf(const basic_stringbuf&) = delete;
   basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); }
 
 #if _LIBCPP_STD_VER >= 20
@@ -374,6 +383,7 @@ public:
 #endif
 
   // [stringbuf.assign] Assign and swap:
+  basic_stringbuf& operator=(const basic_stringbuf&) = delete;
   basic_stringbuf& operator=(basic_stringbuf&& __rhs);
   void swap(basic_stringbuf& __rhs)
 #if _LIBCPP_STD_VER >= 20
@@ -822,12 +832,14 @@ public:
       : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
 #endif // _LIBCPP_STD_VER >= 20
 
+  basic_istringstream(const basic_istringstream&) = delete;
   _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs)
       : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
   }
 
   // [istringstream.assign] Assign and swap:
+  basic_istringstream& operator=(const basic_istringstream&) = delete;
   basic_istringstream& operator=(basic_istringstream&& __rhs) {
     basic_istream<char_type, traits_type>::operator=(std::move(__rhs));
     __sb_ = std::move(__rhs.__sb_);
@@ -929,12 +941,14 @@ public:
       : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
 #endif // _LIBCPP_STD_VER >= 20
 
+  basic_ostringstream(const basic_ostringstream&) = delete;
   _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs)
       : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
   }
 
   // [ostringstream.assign] Assign and swap:
+  basic_ostringstream& operator=(const basic_ostringstream&) = delete;
   basic_ostringstream& operator=(basic_ostringstream&& __rhs) {
     basic_ostream<char_type, traits_type>::operator=(std::move(__rhs));
     __sb_ = std::move(__rhs.__sb_);
@@ -1040,12 +1054,14 @@ public:
       : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
 #endif // _LIBCPP_STD_VER >= 20
 
+  basic_stringstream(const basic_stringstream&) = delete;
   _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs)
       : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
   }
 
   // [stringstream.assign] Assign and swap:
+  basic_stringstream& operator=(const basic_stringstream&) = delete;
   basic_stringstream& operator=(basic_stringstream&& __rhs) {
     basic_iostream<char_type, traits_type>::operator=(std::move(__rhs));
     __sb_ = std::move(__rhs.__sb_);
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.assign/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.assign/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..f635006a229c3
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.assign/copy.compile.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringstream
+
+// basic_istringstream& operator=(const basic_istringstream&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_assignable<std::istringstream>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_assignable<std::wistringstream>::value, "");
+#endif
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..41b91b48044c6
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/copy.compile.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringstream
+
+// basic_istringstream(const basic_istringstream&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_constructible<std::istringstream>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible<std::wistringstream>::value, "");
+#endif
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.assign/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.assign/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..350bb8ec36434
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.assign/copy.compile.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringstream
+
+// basic_stringstream& operator=(const basic_stringstream&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_constructible<std::stringstream>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible<std::wstringstream>::value, "");
+#endif
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..decde2d94c665
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/copy.compile.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringstream
+
+// basic_ostringstream(const basic_ostringstream&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_assignable<std::ostringstream>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_assignable<std::wostringstream>::value, "");
+#endif
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..fa2c96af97d21
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/copy.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// basic_stringbuf(const basic_stringbuf&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_assignable<std::basic_stringbuf<char>>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_assignable<std::basic_stringbuf<wchar_t>>::value, "");
+#endif
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..f3670b45bec09
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/copy.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// basic_stringbuf(const basic_stringbuf&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_constructible<std::basic_stringbuf<char>>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible<std::basic_stringbuf<wchar_t>>::value, "");
+#endif
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.assign/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.assign/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..e20ebe2899c3a
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.assign/copy.compile.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringstream
+
+// basic_stringstream& operator=(const basic_stringstream&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_assignable<std::stringstream>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_assignable<std::wstringstream>::value, "");
+#endif
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/copy.compile.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/copy.compile.pass.cpp
new file mode 100644
index 0000000000000..353df09a9a38a
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/copy.compile.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringstream
+
+// basic_stringstream(const basic_stringstream&) = delete;
+
+#include <sstream>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_copy_constructible< std::stringstream>::value, "");
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible< std::wstringstream>::value, "");
+#endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/80254


More information about the libcxx-commits mailing list