Skip to content

Commit 7c88fd8

Browse files
committed
[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
1 parent 7565ae6 commit 7c88fd8

File tree

9 files changed

+204
-0
lines changed

9 files changed

+204
-0
lines changed

libcxx/include/sstream

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ public:
4848
template <class SAlloc>
4949
explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s,
5050
ios_base::openmode which = ios_base::in | ios_base::out); // C++20
51+
basic_istringstream(const basic_istringstream&) = delete;
5152
basic_stringbuf(basic_stringbuf&& rhs);
5253
basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20
5354
5455
// [stringbuf.assign] Assign and swap:
56+
basic_istringstream& operator=(const basic_istringstream&) = delete;
5557
basic_stringbuf& operator=(basic_stringbuf&& rhs);
5658
void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20
5759
@@ -119,9 +121,11 @@ public:
119121
template <class SAlloc>
120122
explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s,
121123
ios_base::openmode which = ios_base::in); // C++20
124+
basic_istringstream(const basic_istringstream&) = delete;
122125
basic_istringstream(basic_istringstream&& rhs);
123126
124127
// [istringstream.assign] Assign and swap:
128+
basic_istringstream& operator=(const basic_istringstream&) = delete;
125129
basic_istringstream& operator=(basic_istringstream&& rhs);
126130
void swap(basic_istringstream& rhs);
127131
@@ -178,9 +182,11 @@ public:
178182
template <class SAlloc>
179183
explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s,
180184
ios_base::openmode which = ios_base::out); // C++20
185+
basic_ostringstream(const basic_ostringstream&) = delete;
181186
basic_ostringstream(basic_ostringstream&& rhs);
182187
183188
// [ostringstream.assign] Assign and swap:
189+
basic_ostringstream& operator=(const basic_ostringstream&) = delete;
184190
basic_ostringstream& operator=(basic_ostringstream&& rhs);
185191
void swap(basic_ostringstream& rhs);
186192
@@ -237,9 +243,11 @@ public:
237243
template <class SAlloc>
238244
explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
239245
ios_base::openmode which = ios_base::out | ios_base::in); // C++20
246+
basic_stringstream(const basic_stringstream&) = delete;
240247
basic_stringstream(basic_stringstream&& rhs);
241248
242249
// [stringstream.assign] Assign and swap:
250+
basic_stringstream& operator=(const basic_stringstream&) = delete;
243251
basic_stringstream& operator=(basic_stringstream&& rhs);
244252
void swap(basic_stringstream& rhs);
245253
@@ -364,6 +372,7 @@ public:
364372
}
365373
#endif // _LIBCPP_STD_VER >= 20
366374

375+
basic_stringbuf(const basic_stringbuf&) = delete;
367376
basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); }
368377

369378
#if _LIBCPP_STD_VER >= 20
@@ -374,6 +383,7 @@ public:
374383
#endif
375384

376385
// [stringbuf.assign] Assign and swap:
386+
basic_stringbuf& operator=(const basic_stringbuf&) = delete;
377387
basic_stringbuf& operator=(basic_stringbuf&& __rhs);
378388
void swap(basic_stringbuf& __rhs)
379389
#if _LIBCPP_STD_VER >= 20
@@ -822,12 +832,14 @@ public:
822832
: basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
823833
#endif // _LIBCPP_STD_VER >= 20
824834

835+
basic_istringstream(const basic_istringstream&) = delete;
825836
_LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs)
826837
: basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
827838
basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
828839
}
829840

830841
// [istringstream.assign] Assign and swap:
842+
basic_istringstream& operator=(const basic_istringstream&) = delete;
831843
basic_istringstream& operator=(basic_istringstream&& __rhs) {
832844
basic_istream<char_type, traits_type>::operator=(std::move(__rhs));
833845
__sb_ = std::move(__rhs.__sb_);
@@ -929,12 +941,14 @@ public:
929941
: basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
930942
#endif // _LIBCPP_STD_VER >= 20
931943

944+
basic_ostringstream(const basic_ostringstream&) = delete;
932945
_LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs)
933946
: basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
934947
basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
935948
}
936949

937950
// [ostringstream.assign] Assign and swap:
951+
basic_ostringstream& operator=(const basic_ostringstream&) = delete;
938952
basic_ostringstream& operator=(basic_ostringstream&& __rhs) {
939953
basic_ostream<char_type, traits_type>::operator=(std::move(__rhs));
940954
__sb_ = std::move(__rhs.__sb_);
@@ -1040,12 +1054,14 @@ public:
10401054
: basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
10411055
#endif // _LIBCPP_STD_VER >= 20
10421056

1057+
basic_stringstream(const basic_stringstream&) = delete;
10431058
_LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs)
10441059
: basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
10451060
basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
10461061
}
10471062

10481063
// [stringstream.assign] Assign and swap:
1064+
basic_stringstream& operator=(const basic_stringstream&) = delete;
10491065
basic_stringstream& operator=(basic_stringstream&& __rhs) {
10501066
basic_iostream<char_type, traits_type>::operator=(std::move(__rhs));
10511067
__sb_ = std::move(__rhs.__sb_);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <sstream>
10+
11+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12+
// class basic_stringstream
13+
14+
// basic_istringstream& operator=(const basic_istringstream&) = delete;
15+
16+
#include <sstream>
17+
#include <type_traits>
18+
19+
static_assert(!std::is_copy_assignable<std::istringstream>::value, "");
20+
21+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
22+
static_assert(!std::is_copy_assignable<std::wistringstream>::value, "");
23+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <sstream>
10+
11+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12+
// class basic_stringstream
13+
14+
// basic_istringstream(const basic_istringstream&) = delete;
15+
16+
#include <sstream>
17+
#include <type_traits>
18+
19+
static_assert(!std::is_copy_constructible<std::istringstream>::value, "");
20+
21+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
22+
static_assert(!std::is_copy_constructible<std::wistringstream>::value, "");
23+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <sstream>
10+
11+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12+
// class basic_stringstream
13+
14+
// basic_stringstream& operator=(const basic_stringstream&) = delete;
15+
16+
#include <sstream>
17+
#include <type_traits>
18+
19+
static_assert(!std::is_copy_constructible<std::stringstream>::value, "");
20+
21+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
22+
static_assert(!std::is_copy_constructible<std::wstringstream>::value, "");
23+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <sstream>
10+
11+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12+
// class basic_stringstream
13+
14+
// basic_ostringstream(const basic_ostringstream&) = delete;
15+
16+
#include <sstream>
17+
#include <type_traits>
18+
19+
static_assert(!std::is_copy_assignable<std::ostringstream>::value, "");
20+
21+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
22+
static_assert(!std::is_copy_assignable<std::wostringstream>::value, "");
23+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// <sstream>
12+
13+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
14+
// class basic_stringbuf
15+
16+
// basic_stringbuf(const basic_stringbuf&) = delete;
17+
18+
#include <sstream>
19+
#include <type_traits>
20+
21+
static_assert(!std::is_copy_assignable<std::basic_stringbuf<char>>::value, "");
22+
23+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
24+
static_assert(!std::is_copy_assignable<std::basic_stringbuf<wchar_t>>::value, "");
25+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// <sstream>
12+
13+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
14+
// class basic_stringbuf
15+
16+
// basic_stringbuf(const basic_stringbuf&) = delete;
17+
18+
#include <sstream>
19+
#include <type_traits>
20+
21+
static_assert(!std::is_copy_constructible<std::basic_stringbuf<char>>::value, "");
22+
23+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
24+
static_assert(!std::is_copy_constructible<std::basic_stringbuf<wchar_t>>::value, "");
25+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <sstream>
10+
11+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12+
// class basic_stringstream
13+
14+
// basic_stringstream& operator=(const basic_stringstream&) = delete;
15+
16+
#include <sstream>
17+
#include <type_traits>
18+
19+
static_assert(!std::is_copy_assignable<std::stringstream>::value, "");
20+
21+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
22+
static_assert(!std::is_copy_assignable<std::wstringstream>::value, "");
23+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <sstream>
10+
11+
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12+
// class basic_stringstream
13+
14+
// basic_stringstream(const basic_stringstream&) = delete;
15+
16+
#include <sstream>
17+
#include <type_traits>
18+
19+
static_assert(!std::is_copy_constructible< std::stringstream>::value, "");
20+
21+
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
22+
static_assert(!std::is_copy_constructible< std::wstringstream>::value, "");
23+
#endif

0 commit comments

Comments
 (0)