[PATCH v3] libstdc++: bitset subscript check when _GLIBCXX_ASSERTIONS [PR118341]

Jakub Jelinek jakub@redhat.com
Fri Mar 6 06:52:49 GMT 2026


On Thu, Mar 05, 2026 at 01:01:39PM -0500, Nathan Myers wrote:
> --- a/libstdc++-v3/include/std/bitset
> +++ b/libstdc++-v3/include/std/bitset
> @@ -1290,11 +1290,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
>        _GLIBCXX23_CONSTEXPR
>        reference
>        operator[](size_t __position)
> -      { return reference(*this, __position); }
> +      {
> +	__glibcxx_assert(__position < _Nb);
> +	return reference(*this, __position);
> +      }
>  
>        _GLIBCXX_CONSTEXPR bool
>        operator[](size_t __position) const
> -      { return _Unchecked_test(__position); }
> +      {
> +	__glibcxx_assert(__position < _Nb);
> +	return _Unchecked_test(__position);
> +      }
>        ///@}
>  
>        /**

This second change broke
In file included from /home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stdexcept_throw.h:34,
                 from /home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/bitset:49,
                 from /home/jakub/src/gcc/gcc/testsuite/g++.old-deja/g++.martin/bitset1.C:3:
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/bitset: In member function 'constexpr bool std::bitset<_Nb>::operator[](std::size_t) const':
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/c++config.h:646:6: error: compound-statement in 'constexpr' function [-Wpedantic]
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/bitset:1301:9: note: in expansion of macro '__glibcxx_assert'
compiler exited with status 1
FAIL: g++.old-deja/g++.martin/bitset1.C  -std=c++11 (test for excess errors)
Excess errors:
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/c++config.h:646:6: error: compound-statement in 'constexpr' function [-Wpedantic]

UNRESOLVED: g++.old-deja/g++.martin/bitset1.C  -std=c++11 compilation failed to produce executable
and
In file included from /home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:59,
                 from /home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/algorithm:62,
                 from /home/jakub/src/gcc/gcc/testsuite/g++.old-deja/g++.other/headers1.C:9:
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/bitset: In member function 'constexpr bool std::bitset<_Nb>::operator[](std::size_t) const':
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/c++config.h:646:6: error: compound-statement in 'constexpr' function [-Wpedantic]
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/bitset:1301:9: note: in expansion of macro '__glibcxx_assert'
compiler exited with status 1
FAIL: g++.old-deja/g++.other/headers1.C  -std=c++11 (test for excess errors)
Excess errors:
/home/jakub/src/gcc/obj16/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/c++config.h:646:6: error: compound-statement in 'constexpr' function [-Wpedantic]

UNRESOLVED: g++.old-deja/g++.other/headers1.C  -std=c++11 compilation failed to produce executable

Perhaps the assert needs to be omitted for C++11 (C++98 is fine because the
operator isn't constexpr in that case)?

	Jakub



More information about the Libstdc++ mailing list