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

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 31 23:25:20 PST 2024


https://github.com/H-G-Hristov created https://github.com/llvm/llvm-project/pull/80254

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

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

>From efd6caed78da34bc9c284aa8739ba160a08fb543 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 31 Jan 2024 12:33:05 +0200
Subject: [PATCH] [libc++][sstream] Add deleted special member functions

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

References:
- https://eel.is/c++draft/string.streams
---
 libcxx/include/sstream                        | 16 ++++++++++++
 .../copy.compile.pass.cpp                     | 23 +++++++++++++++++
 .../istringstream.cons/copy.compile.pass.cpp  | 23 +++++++++++++++++
 .../copy.compile.pass.cpp                     | 23 +++++++++++++++++
 .../ostringstream.cons/copy.compile.pass.cpp  | 23 +++++++++++++++++
 .../stringbuf.assign/copy.compile.pass.cpp    | 25 +++++++++++++++++++
 .../stringbuf.cons/copy.compile.pass.cpp      | 25 +++++++++++++++++++
 .../stringstream.assign/copy.compile.pass.cpp | 23 +++++++++++++++++
 .../stringstream.cons/copy.compile.pass.cpp   | 23 +++++++++++++++++
 9 files changed, 204 insertions(+)
 create mode 100644 libcxx/test/std/input.output/string.streams/istringstream/istringstream.assign/copy.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/copy.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.assign/copy.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/copy.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/copy.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/copy.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/string.streams/stringstream/stringstream.assign/copy.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/copy.compile.pass.cpp

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..1697cfaf85356
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.assign/copy.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+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..0f68a8270e718
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/copy.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+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..8e2ffd852c25b
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.assign/copy.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+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..1533380c77792
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/copy.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+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..2756e0d7f773e
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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
+//
+//===----------------------------------------------------------------------===//
+
+// 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>
+
+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..1c779d5610707
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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
+//
+//===----------------------------------------------------------------------===//
+
+// 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>
+
+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..82038deb14f08
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.assign/copy.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+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..99d2a93de9b04
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/copy.compile.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+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



More information about the libcxx-commits mailing list