[committed] libstdc++: Add #if around non-C++03 code in std::bitset [PR107037]

Message ID 20220926125953.2149422-1-jwakely@redhat.com
State New, archived
Headers
Series [committed] libstdc++: Add #if around non-C++03 code in std::bitset [PR107037] |

Commit Message

Jonathan Wakely Sept. 26, 2022, 12:59 p.m. UTC
  Tested x86_64-linux, pushed to trunk.

-- >8 --

libstdc++-v3/ChangeLog:

	PR libstdc++/107037
	* include/std/bitset (_Base_bitset::_M_do_reset): Use
	preprocessor conditional around non-C++03 code.
	* testsuite/20_util/bitset/107037.cc: New test.
---
 libstdc++-v3/include/std/bitset                 | 5 +++--
 libstdc++-v3/testsuite/20_util/bitset/107037.cc | 7 +++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/20_util/bitset/107037.cc
  

Patch

diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 6dbc58c6429..1a551cf9785 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -182,13 +182,14 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _GLIBCXX14_CONSTEXPR void
       _M_do_reset() _GLIBCXX_NOEXCEPT
       {
+#if __cplusplus >= 201402L
 	if (__builtin_is_constant_evaluated())
 	  {
 	    for (_WordT& __w : _M_w)
 	      __w = 0;
 	    return;
 	  }
-
+#endif
 	__builtin_memset(_M_w, 0, _Nw * sizeof(_WordT));
       }
 
@@ -1680,7 +1681,7 @@  _GLIBCXX_END_NAMESPACE_VERSION
 
 #endif // C++11
 
-#ifdef _GLIBCXX_DEBUG && _GLIBCXX_HOSTED
+#if defined _GLIBCXX_DEBUG && _GLIBCXX_HOSTED
 # include <debug/bitset>
 #endif
 
diff --git a/libstdc++-v3/testsuite/20_util/bitset/107037.cc b/libstdc++-v3/testsuite/20_util/bitset/107037.cc
new file mode 100644
index 00000000000..b4560dd3775
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/bitset/107037.cc
@@ -0,0 +1,7 @@ 
+// { dg-options "-std=c++03" }
+// { dg-do compile }
+// PR libstdc++/107037 bitset::_M_do_reset fails for strict -std=c++03 mode
+#include <bitset>
+template class std::bitset<0>;
+template class std::bitset<1>;
+template class std::bitset<100>;