[PATCH] P0935R0 Eradicating unnecessarily explicit default constructors
Jonathan Wakely
jwakely@redhat.com
Fri Jul 6 12:39:00 GMT 2018
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.
Tested powerpc64le-linux, committed to trunk.
-------------- next part --------------
commit 650035269ded698f16e66fa04f8d21dcb1b94fa8
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Jul 6 11:38:57 2018 +0100
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.
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 521cebf1f80..e634d3ab707 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1748,10 +1748,20 @@ GLIBCXX_3.4.21 {
_ZStplI[cw]St11char_traitsI[cw]ESaI[cw]EENSt7__cxx1112basic_stringIT_T0_T1_EE*;
# ABI-tagged stringstreams
- _ZNSt7__cxx1115basic_stringbuf*;
- _ZNSt7__cxx1118basic_stringstream*;
- _ZNSt7__cxx1119basic_istringstream*;
- _ZNSt7__cxx1119basic_ostringstream*;
+# _ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]*;
+ _ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[ORS]*;
+ _ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EED[012]Ev;
+ _ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]*__xfer_bufptrs*;
+ _ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EE[a1346789]*;
+# _ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]*;
+ _ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[ORS]*;
+ _ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EED[012]Ev;
+ _ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EE[a34]*;
+# _ZNSt7__cxx1119basic_istringstreamI[cw]St11char_traitsI[cw]*;
+# _ZNSt7__cxx1119basic_ostringstreamI[cw]St11char_traitsI[cw]*;
+ _ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]E[ORS]*;
+ _ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EED[012]Ev;
+ _ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EE[a34]*;
_ZNKSt7__cxx1115basic_stringbuf*;
_ZNKSt7__cxx1118basic_stringstream*;
_ZNKSt7__cxx1119basic_istringstream*;
@@ -2021,6 +2031,14 @@ GLIBCXX_3.4.26 {
_ZNSt13runtime_errorC[12]EOS_;
_ZNSt13runtime_erroraSEOS_;
+ # Default constructors for stringstreams
+ _ZNSt15basic_stringbuf[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
+ _ZNSt18basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
+ _ZNSt19basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
+ _ZNSt7__cxx1115basic_stringbuf[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
+ _ZNSt7__cxx1118basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
+ _ZNSt7__cxx1119basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]Ev;
+
} GLIBCXX_3.4.25;
# Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index 8ad18d00fb6..71d69e94b65 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -89,6 +89,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
public:
// Constructors:
+
+ /**
+ * @brief Starts with an empty string buffer.
+ *
+ * The default constructor initializes the parent class using its
+ * own default ctor.
+ */
+ basic_stringbuf()
+ : __streambuf_type(), _M_mode(ios_base::in | ios_base::out), _M_string()
+ { }
+
/**
* @brief Starts with an empty string buffer.
* @param __mode Whether the buffer can read, or write, or both.
@@ -97,7 +108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* own default ctor.
*/
explicit
- basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
+ basic_stringbuf(ios_base::openmode __mode)
: __streambuf_type(), _M_mode(__mode), _M_string()
{ }
@@ -401,8 +412,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
public:
// Constructors:
+
/**
* @brief Default constructor starts with an empty string buffer.
+ *
+ * Initializes @c sb using @c in, and passes @c &sb to the base
+ * class initializer. Does not allocate any buffer.
+ *
+ * That's a lie. We initialize the base class with NULL, because the
+ * string class does its own memory management.
+ */
+ basic_istringstream()
+ : __istream_type(), _M_stringbuf(ios_base::in)
+ { this->init(&_M_stringbuf); }
+
+ /**
+ * @brief Starts with an empty string buffer.
* @param __mode Whether the buffer can read, or write, or both.
*
* @c ios_base::in is automatically included in @a __mode.
@@ -414,7 +439,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* string class does its own memory management.
*/
explicit
- basic_istringstream(ios_base::openmode __mode = ios_base::in)
+ basic_istringstream(ios_base::openmode __mode)
: __istream_type(), _M_stringbuf(__mode | ios_base::in)
{ this->init(&_M_stringbuf); }
@@ -545,8 +570,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
public:
// Constructors/destructor:
+
/**
* @brief Default constructor starts with an empty string buffer.
+ *
+ * Initializes @c sb using @c mode|out, and passes @c &sb to the base
+ * class initializer. Does not allocate any buffer.
+ *
+ * That's a lie. We initialize the base class with NULL, because the
+ * string class does its own memory management.
+ */
+ basic_ostringstream()
+ : __ostream_type(), _M_stringbuf(ios_base::out)
+ { this->init(&_M_stringbuf); }
+
+ /**
+ * @brief Starts with an empty string buffer.
* @param __mode Whether the buffer can read, or write, or both.
*
* @c ios_base::out is automatically included in @a mode.
@@ -558,7 +597,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* string class does its own memory management.
*/
explicit
- basic_ostringstream(ios_base::openmode __mode = ios_base::out)
+ basic_ostringstream(ios_base::openmode __mode)
: __ostream_type(), _M_stringbuf(__mode | ios_base::out)
{ this->init(&_M_stringbuf); }
@@ -689,19 +728,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
public:
// Constructors/destructors
+
/**
* @brief Default constructor starts with an empty string buffer.
+ *
+ * Initializes @c sb using the mode @c in|out, and passes @c &sb
+ * to the base class initializer. Does not allocate any buffer.
+ *
+ * That's a lie. We initialize the base class with NULL, because the
+ * string class does its own memory management.
+ */
+ basic_stringstream()
+ : __iostream_type(), _M_stringbuf(ios_base::out | ios_base::in)
+ { this->init(&_M_stringbuf); }
+
+ /**
+ * @brief Starts with an empty string buffer.
* @param __m Whether the buffer can read, or write, or both.
*
- * Initializes @c sb using the mode from @c __m, and passes @c
- * &sb to the base class initializer. Does not allocate any
- * buffer.
+ * Initializes @c sb using the mode from @c __m, and passes @c &sb
+ * to the base class initializer. Does not allocate any buffer.
*
* That's a lie. We initialize the base class with NULL, because the
* string class does its own memory management.
*/
explicit
- basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
+ basic_stringstream(ios_base::openmode __m)
: __iostream_type(), _M_stringbuf(__m)
{ this->init(&_M_stringbuf); }
diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/default.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/default.cc
new file mode 100644
index 00000000000..020206fcc84
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/default.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++11 27.8.3.1 basic_istringstream constructors [istringstream.cons]
+
+// { dg-do run { target c++11 } }
+
+#include <sstream>
+#include <testsuite_common_types.h>
+
+void test01()
+{
+ // P0935R0
+ __gnu_test::implicitly_default_constructible test;
+ test.operator()<std::istringstream>();
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/default.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/default.cc
new file mode 100644
index 00000000000..f2768b02992
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/default.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++11 27.8.4.1 basic_ostringstream constructors [ostringstream.cons]
+
+// { dg-do run { target c++11 } }
+
+#include <sstream>
+#include <testsuite_common_types.h>
+
+void test01()
+{
+ // P0935R0
+ __gnu_test::implicitly_default_constructible test;
+ test.operator()<std::ostringstream>();
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/default.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/default.cc
new file mode 100644
index 00000000000..06b242f8295
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/default.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++11 27.8.2.1 basic_stringbuf constructors [stringbuf.cons]
+
+// { dg-do run { target c++11 } }
+
+#include <sstream>
+#include <testsuite_common_types.h>
+
+void test01()
+{
+ // P0935R0
+ __gnu_test::implicitly_default_constructible test;
+ test.operator()<std::stringbuf>();
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/default.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/default.cc
new file mode 100644
index 00000000000..6ac75ab65c3
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/default.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++11 27.8.2.1 basic_stringbuf constructors [stringbuf.cons]
+
+// { dg-do run { target c++11 } }
+
+#include <sstream>
+#include <testsuite_common_types.h>
+
+void test01()
+{
+ // P0935R0
+ __gnu_test::implicitly_default_constructible test;
+ test.operator()<std::wstringbuf>();
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/default.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/default.cc
new file mode 100644
index 00000000000..0195be15dfb
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/default.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++11 27.8.5.1 basic_stringstream constructors [stringstream.cons]
+
+// { dg-do run { target c++11 } }
+
+#include <sstream>
+#include <testsuite_common_types.h>
+
+void test01()
+{
+ // P0935R0
+ __gnu_test::implicitly_default_constructible test;
+ test.operator()<std::stringstream>();
+}
+
+int main()
+{
+ test01();
+}
More information about the Libstdc++
mailing list