libstdc++: bitset _GLIBCXX_ASSERTIONS op[] fixes

C++11 forbids a compound statement, as seen in the definition
of __glibcxx_assert(), in a constexpr function. This patch
open-codes the assertion in `bitset<>::operator[] const` for
C++11 to fix a failure in `g++.old-deja/g++.martin/bitset1.C`.

Also, it adds `{ dg-do compile }` in another test to suppress
a spurious UNRESOLVED complaint.

libstdc++-v3/ChangeLog:
	* include/std/bitset (operator[]() const): Customize bounds
	check for C++11 case.
	* testsuite/20_util/bitset/access/subscript_const_neg.cc:
	Suppress UNRESOLVED complaint.
This commit is contained in:
Nathan Myers
2026-03-06 05:33:04 -05:00
parent e1077ad575
commit 2bfaa218b0
2 changed files with 9 additions and 0 deletions

View File

@@ -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(), false);
#else
return _Unchecked_test(__position);
#endif
}
///@}

View File

@@ -1,3 +1,4 @@
// { dg-do compile }
#include <bitset>
void test_const_subscript_assignment()