On Fri, Mar 06, 2026 at 05:42:07AM -0500, Nathan Myers wrote:
> [This is untested. How do I find g++.old-deja/g++.martin/bitset1.C ?]

GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make check-g++ 
RUNTESTFLAGS="old-deja.exp='g++.martin/bitset1.C g++.other/headers1.C'"
in the gcc build directory.

> 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
>        }
>        ///@}

        Jakub

Reply via email to