On Fri, 6 Mar 2026 at 11:42, Nathan Myers <[email protected]> wrote:
>
> Changes in v2:
>  - Tested.
>  - Also patch up UNRESOLVED complaint about subscript_const_neg.cc.
>
> 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.
> ---
>  libstdc++-v3/include/std/bitset                           | 8 ++++++++
>  .../20_util/bitset/access/subscript_const_neg.cc          | 1 +
>  2 files changed, 9 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());

Please use 'false' here instead of 'bool()'

OK with that change, thanks.

> +#else
> +       return _Unchecked_test(__position);
> +#endif
>        }
>        ///@}
>
> diff --git 
> a/libstdc++-v3/testsuite/20_util/bitset/access/subscript_const_neg.cc 
> b/libstdc++-v3/testsuite/20_util/bitset/access/subscript_const_neg.cc
> index 12d4f1eaf30..a5676d54a5e 100644
> --- a/libstdc++-v3/testsuite/20_util/bitset/access/subscript_const_neg.cc
> +++ b/libstdc++-v3/testsuite/20_util/bitset/access/subscript_const_neg.cc
> @@ -1,3 +1,4 @@
> +// { dg-do compile }
>  #include <bitset>
>
>  void test_const_subscript_assignment()
> --
> 2.52.0
>

Reply via email to