Skip to content

Commit 8cffd3e

Browse files
author
redi
committed
P0935R0 Eradicating unnecessarily explicit default constructors
This is the last remaining piece of P0935R0. This adds a default constructor to each of the streambuf and stream types in <sstream> so that default construction does not use the 'explicit' constructor that has a single, defaulted argument. P0935R0 Eradicating unnecessarily explicit default constructors * config/abi/pre/gnu.ver: Tighten existing patterns and export new default constructor symbols. * include/std/sstream (basic_stringbuf, basic_istringstream) (basic_ostringstream, basic_stringstream): Remove default arguments from explicit constructors taking ios_base::openmode and add separate non-explicit default constructors. * testsuite/27_io/basic_istringstream/cons/default.cc: New. * testsuite/27_io/basic_ostringstream/cons/default.cc: New. * testsuite/27_io/basic_stringstream/cons/default.cc: New. * testsuite/27_io/basic_stringbuf/cons/char/default.cc: New. * testsuite/27_io/basic_stringbuf/cons/wchar_t/default.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@262474 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent a01fc43 commit 8cffd3e

File tree

8 files changed

+269
-11
lines changed

8 files changed

+269
-11
lines changed

libstdc++-v3/ChangeLog

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
2018-07-06 Jonathan Wakely <[email protected]>
22

3+
P0935R0 Eradicating unnecessarily explicit default constructors
4+
* config/abi/pre/gnu.ver: Tighten existing patterns and export new
5+
default constructor symbols.
6+
* include/std/sstream (basic_stringbuf, basic_istringstream)
7+
(basic_ostringstream, basic_stringstream): Remove default arguments
8+
from explicit constructors taking ios_base::openmode and add separate
9+
non-explicit default constructors.
10+
* testsuite/27_io/basic_istringstream/cons/default.cc: New.
11+
* testsuite/27_io/basic_ostringstream/cons/default.cc: New.
12+
* testsuite/27_io/basic_stringstream/cons/default.cc: New.
13+
* testsuite/27_io/basic_stringbuf/cons/char/default.cc: New.
14+
* testsuite/27_io/basic_stringbuf/cons/wchar_t/default.cc: New.
15+
316
* include/std/variant (__accepted_index): Use void_t.
417

518
2018-07-05 Jonathan Wakely <[email protected]>

libstdc++-v3/config/abi/pre/gnu.ver

+22-4
Original file line numberDiff line numberDiff line change
@@ -1748,10 +1748,20 @@ GLIBCXX_3.4.21 {
17481748
_ZStplI[cw]St11char_traitsI[cw]ESaI[cw]EENSt7__cxx1112basic_stringIT_T0_T1_EE*;
17491749

17501750
# ABI-tagged stringstreams
1751-
_ZNSt7__cxx1115basic_stringbuf*;
1752-
_ZNSt7__cxx1118basic_stringstream*;
1753-
_ZNSt7__cxx1119basic_istringstream*;
1754-
_ZNSt7__cxx1119basic_ostringstream*;
1751+
# _ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]*;
1752+
_ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[ORS]*;
1753+
_ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EED[012]Ev;
1754+
_ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]*__xfer_bufptrs*;
1755+
_ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EE[a1346789]*;
1756+
# _ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]*;
1757+
_ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[ORS]*;
1758+
_ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EED[012]Ev;
1759+
_ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EE[a34]*;
1760+
# _ZNSt7__cxx1119basic_istringstreamI[cw]St11char_traitsI[cw]*;
1761+
# _ZNSt7__cxx1119basic_ostringstreamI[cw]St11char_traitsI[cw]*;
1762+
_ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[ORS]*;
1763+
_ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EED[012]Ev;
1764+
_ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EE[a34]*;
17551765
_ZNKSt7__cxx1115basic_stringbuf*;
17561766
_ZNKSt7__cxx1118basic_stringstream*;
17571767
_ZNKSt7__cxx1119basic_istringstream*;
@@ -2021,6 +2031,14 @@ GLIBCXX_3.4.26 {
20212031
_ZNSt13runtime_errorC[12]EOS_;
20222032
_ZNSt13runtime_erroraSEOS_;
20232033

2034+
# Default constructors for stringstreams
2035+
_ZNSt15basic_stringbuf[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
2036+
_ZNSt18basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
2037+
_ZNSt19basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
2038+
_ZNSt7__cxx1115basic_stringbuf[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
2039+
_ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
2040+
_ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
2041+
20242042
} GLIBCXX_3.4.25;
20252043

20262044
# Symbols in the support library (libsupc++) have their own tag.

libstdc++-v3/include/std/sstream

+59-7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
8989

9090
public:
9191
// Constructors:
92+
93+
/**
94+
* @brief Starts with an empty string buffer.
95+
*
96+
* The default constructor initializes the parent class using its
97+
* own default ctor.
98+
*/
99+
basic_stringbuf()
100+
: __streambuf_type(), _M_mode(ios_base::in | ios_base::out), _M_string()
101+
{ }
102+
92103
/**
93104
* @brief Starts with an empty string buffer.
94105
* @param __mode Whether the buffer can read, or write, or both.
@@ -97,7 +108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
97108
* own default ctor.
98109
*/
99110
explicit
100-
basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
111+
basic_stringbuf(ios_base::openmode __mode)
101112
: __streambuf_type(), _M_mode(__mode), _M_string()
102113
{ }
103114

@@ -401,8 +412,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
401412

402413
public:
403414
// Constructors:
415+
404416
/**
405417
* @brief Default constructor starts with an empty string buffer.
418+
*
419+
* Initializes @c sb using @c in, and passes @c &sb to the base
420+
* class initializer. Does not allocate any buffer.
421+
*
422+
* That's a lie. We initialize the base class with NULL, because the
423+
* string class does its own memory management.
424+
*/
425+
basic_istringstream()
426+
: __istream_type(), _M_stringbuf(ios_base::in)
427+
{ this->init(&_M_stringbuf); }
428+
429+
/**
430+
* @brief Starts with an empty string buffer.
406431
* @param __mode Whether the buffer can read, or write, or both.
407432
*
408433
* @c ios_base::in is automatically included in @a __mode.
@@ -414,7 +439,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
414439
* string class does its own memory management.
415440
*/
416441
explicit
417-
basic_istringstream(ios_base::openmode __mode = ios_base::in)
442+
basic_istringstream(ios_base::openmode __mode)
418443
: __istream_type(), _M_stringbuf(__mode | ios_base::in)
419444
{ this->init(&_M_stringbuf); }
420445

@@ -545,8 +570,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
545570

546571
public:
547572
// Constructors/destructor:
573+
548574
/**
549575
* @brief Default constructor starts with an empty string buffer.
576+
*
577+
* Initializes @c sb using @c mode|out, and passes @c &sb to the base
578+
* class initializer. Does not allocate any buffer.
579+
*
580+
* That's a lie. We initialize the base class with NULL, because the
581+
* string class does its own memory management.
582+
*/
583+
basic_ostringstream()
584+
: __ostream_type(), _M_stringbuf(ios_base::out)
585+
{ this->init(&_M_stringbuf); }
586+
587+
/**
588+
* @brief Starts with an empty string buffer.
550589
* @param __mode Whether the buffer can read, or write, or both.
551590
*
552591
* @c ios_base::out is automatically included in @a mode.
@@ -558,7 +597,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
558597
* string class does its own memory management.
559598
*/
560599
explicit
561-
basic_ostringstream(ios_base::openmode __mode = ios_base::out)
600+
basic_ostringstream(ios_base::openmode __mode)
562601
: __ostream_type(), _M_stringbuf(__mode | ios_base::out)
563602
{ this->init(&_M_stringbuf); }
564603

@@ -689,19 +728,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
689728

690729
public:
691730
// Constructors/destructors
731+
692732
/**
693733
* @brief Default constructor starts with an empty string buffer.
734+
*
735+
* Initializes @c sb using the mode @c in|out, and passes @c &sb
736+
* to the base class initializer. Does not allocate any buffer.
737+
*
738+
* That's a lie. We initialize the base class with NULL, because the
739+
* string class does its own memory management.
740+
*/
741+
basic_stringstream()
742+
: __iostream_type(), _M_stringbuf(ios_base::out | ios_base::in)
743+
{ this->init(&_M_stringbuf); }
744+
745+
/**
746+
* @brief Starts with an empty string buffer.
694747
* @param __m Whether the buffer can read, or write, or both.
695748
*
696-
* Initializes @c sb using the mode from @c __m, and passes @c
697-
* &sb to the base class initializer. Does not allocate any
698-
* buffer.
749+
* Initializes @c sb using the mode from @c __m, and passes @c &sb
750+
* to the base class initializer. Does not allocate any buffer.
699751
*
700752
* That's a lie. We initialize the base class with NULL, because the
701753
* string class does its own memory management.
702754
*/
703755
explicit
704-
basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
756+
basic_stringstream(ios_base::openmode __m)
705757
: __iostream_type(), _M_stringbuf(__m)
706758
{ this->init(&_M_stringbuf); }
707759

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2018 Free Software Foundation, Inc.
2+
//
3+
// This file is part of the GNU ISO C++ Library. This library is free
4+
// software; you can redistribute it and/or modify it under the
5+
// terms of the GNU General Public License as published by the
6+
// Free Software Foundation; either version 3, or (at your option)
7+
// any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License along
15+
// with this library; see the file COPYING3. If not see
16+
// <http://www.gnu.org/licenses/>.
17+
18+
// C++11 27.8.3.1 basic_istringstream constructors [istringstream.cons]
19+
20+
// { dg-do run { target c++11 } }
21+
22+
#include <sstream>
23+
#include <testsuite_common_types.h>
24+
25+
void test01()
26+
{
27+
// P0935R0
28+
__gnu_test::implicitly_default_constructible test;
29+
test.operator()<std::istringstream>();
30+
}
31+
32+
int main()
33+
{
34+
test01();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2018 Free Software Foundation, Inc.
2+
//
3+
// This file is part of the GNU ISO C++ Library. This library is free
4+
// software; you can redistribute it and/or modify it under the
5+
// terms of the GNU General Public License as published by the
6+
// Free Software Foundation; either version 3, or (at your option)
7+
// any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License along
15+
// with this library; see the file COPYING3. If not see
16+
// <http://www.gnu.org/licenses/>.
17+
18+
// C++11 27.8.4.1 basic_ostringstream constructors [ostringstream.cons]
19+
20+
// { dg-do run { target c++11 } }
21+
22+
#include <sstream>
23+
#include <testsuite_common_types.h>
24+
25+
void test01()
26+
{
27+
// P0935R0
28+
__gnu_test::implicitly_default_constructible test;
29+
test.operator()<std::ostringstream>();
30+
}
31+
32+
int main()
33+
{
34+
test01();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2018 Free Software Foundation, Inc.
2+
//
3+
// This file is part of the GNU ISO C++ Library. This library is free
4+
// software; you can redistribute it and/or modify it under the
5+
// terms of the GNU General Public License as published by the
6+
// Free Software Foundation; either version 3, or (at your option)
7+
// any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License along
15+
// with this library; see the file COPYING3. If not see
16+
// <http://www.gnu.org/licenses/>.
17+
18+
// C++11 27.8.2.1 basic_stringbuf constructors [stringbuf.cons]
19+
20+
// { dg-do run { target c++11 } }
21+
22+
#include <sstream>
23+
#include <testsuite_common_types.h>
24+
25+
void test01()
26+
{
27+
// P0935R0
28+
__gnu_test::implicitly_default_constructible test;
29+
test.operator()<std::stringbuf>();
30+
}
31+
32+
int main()
33+
{
34+
test01();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2018 Free Software Foundation, Inc.
2+
//
3+
// This file is part of the GNU ISO C++ Library. This library is free
4+
// software; you can redistribute it and/or modify it under the
5+
// terms of the GNU General Public License as published by the
6+
// Free Software Foundation; either version 3, or (at your option)
7+
// any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License along
15+
// with this library; see the file COPYING3. If not see
16+
// <http://www.gnu.org/licenses/>.
17+
18+
// C++11 27.8.2.1 basic_stringbuf constructors [stringbuf.cons]
19+
20+
// { dg-do run { target c++11 } }
21+
22+
#include <sstream>
23+
#include <testsuite_common_types.h>
24+
25+
void test01()
26+
{
27+
// P0935R0
28+
__gnu_test::implicitly_default_constructible test;
29+
test.operator()<std::wstringbuf>();
30+
}
31+
32+
int main()
33+
{
34+
test01();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2018 Free Software Foundation, Inc.
2+
//
3+
// This file is part of the GNU ISO C++ Library. This library is free
4+
// software; you can redistribute it and/or modify it under the
5+
// terms of the GNU General Public License as published by the
6+
// Free Software Foundation; either version 3, or (at your option)
7+
// any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License along
15+
// with this library; see the file COPYING3. If not see
16+
// <http://www.gnu.org/licenses/>.
17+
18+
// C++11 27.8.5.1 basic_stringstream constructors [stringstream.cons]
19+
20+
// { dg-do run { target c++11 } }
21+
22+
#include <sstream>
23+
#include <testsuite_common_types.h>
24+
25+
void test01()
26+
{
27+
// P0935R0
28+
__gnu_test::implicitly_default_constructible test;
29+
test.operator()<std::stringstream>();
30+
}
31+
32+
int main()
33+
{
34+
test01();
35+
}

0 commit comments

Comments
 (0)