[This is untested. How do I find g++.old-deja/g++.martin/bitset1.C ?]

C++11 forbids a compound statement, as seen in the definition of
__glibcxx_assert(), in a constexpr function. This patch implements
the assertion in `bitset<>::operator[] const` directly for C++11,
albeit less ergonomically.

libstdc++-v3/ChangeLog:
        * include/std/bitset (operator[]() const): Customize bounds
        check for C++11 case.
---
 libstdc++-v3/include/std/bitset | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index eb200ab9246..a23545320ee 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -1298,8 +1298,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _GLIBCXX_CONSTEXPR bool
       operator[](size_t __position) const
       {
+#if __cplusplus != 201103L
        __glibcxx_assert(__position < _Nb);
        return _Unchecked_test(__position);
+#elif defined(_GLIBCXX_ASSERTIONS)
+       // C++11 forbids a compound stmt in a constexpr function.
+       return __position < _Nb ? _Unchecked_test(__position)
+         : (__builtin_trap(), bool());
+#else
+       return _Unchecked_test(__position);
+#endif
       }
       ///@}
 
-- 
2.52.0

Reply via email to