This PR is a follow-up to the recently merged #31244, and provides a workaround for affected GCC compilers, similar to #31493.
Without this workaround, building the master branch using GCC 13 or 14 with the -D_GLIBCXX_DEBUG
flag fails with the following error:
0$ cmake -B build -DAPPEND_CPPFLAGS="-D_GLIBCXX_DEBUG"
1-- The CXX compiler identification is GNU 13.3.0
2<snip>
3$ cmake --build build
4[2/10] Building CXX object src/CMakeFiles/bitcoin_common.dir/musig.cpp.o
5FAILED: src/CMakeFiles/bitcoin_common.dir/musig.cpp.o
6/usr/bin/ccache /usr/bin/c++ -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_NO_CXX98_FUNCTION_BASE -I/home/hebasto/dev/bitcoin/build/src -I/home/hebasto/dev/bitcoin/src -I/home/hebasto/dev/bitcoin/src/univalue/include -I/home/hebasto/dev/bitcoin/src/secp256k1/include -O2 -g -std=c++20 -fPIC -fno-extended-identifiers -fdebug-prefix-map=/home/hebasto/dev/bitcoin/src=. -fmacro-prefix-map=/home/hebasto/dev/bitcoin/src=. -fstack-reuse=none -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wno-unused-parameter -MD -MT src/CMakeFiles/bitcoin_common.dir/musig.cpp.o -MF src/CMakeFiles/bitcoin_common.dir/musig.cpp.o.d -o src/CMakeFiles/bitcoin_common.dir/musig.cpp.o -c /home/hebasto/dev/bitcoin/src/musig.cpp -D_GLIBCXX_DEBUG
7In file included from /usr/include/c++/13/debug/stl_iterator.h:32,
8 from /usr/include/c++/13/bits/stl_iterator.h:3003,
9 from /usr/include/c++/13/string:48,
10 from ../src/crypto/sha256.h:10,
11 from ../src/hash.h:12,
12 from ../src/pubkey.h:10,
13 from ../src/musig.h:8,
14 from ../src/musig.cpp:5:
15../src/musig.h:17:108: in ‘constexpr’ expansion of ‘std::span<const unsigned char>(util::hex_literals::operator""_hex_u8<util::detail::Hex<65>{std::array<std::byte, 32>{std::__array_traits<std::byte, 32>::_Type{(std::byte)134, (std::byte)128, (std::byte)135, (std::byte)202, (std::byte)2, (std::byte)166, (std::byte)249, (std::byte)116, (std::byte)196, (std::byte)89, (std::byte)137, (std::byte)36, (std::byte)195, (std::byte)107, (std::byte)87, (std::byte)118, (std::byte)45, (std::byte)50, (std::byte)203, (std::byte)69, (std::byte)113, (std::byte)113, (std::byte)103, (std::byte)227, (std::byte)0, (std::byte)98, (std::byte)44, (std::byte)113, (std::byte)103, (std::byte)227, (std::byte)137, (std::byte)101}}}>())’
16/usr/include/c++/13/span:204:57: in ‘constexpr’ expansion of ‘((std::span<const unsigned char>*)this)->std::span<const unsigned char>::span<const unsigned char*>((& __arr)->std::array<unsigned char, 32>::data(), 32)’
17/usr/include/c++/13/span:167:4: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range<const unsigned char*>(__first, (__first + ((sizetype)__count)))’
18/usr/include/c++/13/debug/helper_functions.h:267:44: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (_Integral(), _Integral()))’
19/usr/include/c++/13/debug/helper_functions.h:197:44: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (std::__iterator_category<const unsigned char*>(__first), std::iterator_traits<const unsigned char*>::iterator_category()))’
20/usr/include/c++/13/debug/helper_functions.h:183:44: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (std::input_iterator_tag(), std::input_iterator_tag()))’
21/usr/include/c++/13/debug/helper_functions.h:143:20: error: ‘(((const unsigned char*)(&<anonymous>.std::array<unsigned char, 32>::_M_elems)) == 0)’ is not a constant expression
22 143 | { return __ptr == 0; }
23 | ~~~~~~^~~~
24[3/10] Building CXX object src/CMakeFiles/bitcoin_common.dir/script/descriptor.cpp.o
25FAILED: src/CMakeFiles/bitcoin_common.dir/script/descriptor.cpp.o
26/usr/bin/ccache /usr/bin/c++ -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_NO_CXX98_FUNCTION_BASE -I/home/hebasto/dev/bitcoin/build/src -I/home/hebasto/dev/bitcoin/src -I/home/hebasto/dev/bitcoin/src/univalue/include -I/home/hebasto/dev/bitcoin/src/secp256k1/include -O2 -g -std=c++20 -fPIC -fno-extended-identifiers -fdebug-prefix-map=/home/hebasto/dev/bitcoin/src=. -fmacro-prefix-map=/home/hebasto/dev/bitcoin/src=. -fstack-reuse=none -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wno-unused-parameter -MD -MT src/CMakeFiles/bitcoin_common.dir/script/descriptor.cpp.o -MF src/CMakeFiles/bitcoin_common.dir/script/descriptor.cpp.o.d -o src/CMakeFiles/bitcoin_common.dir/script/descriptor.cpp.o -c /home/hebasto/dev/bitcoin/src/script/descriptor.cpp -D_GLIBCXX_DEBUG
27In file included from /usr/include/c++/13/debug/stl_iterator.h:32,
28 from /usr/include/c++/13/bits/stl_iterator.h:3003,
29 from /usr/include/c++/13/string:48,
30 from ../src/crypto/sha256.h:10,
31 from ../src/hash.h:12,
32 from ../src/pubkey.h:10,
33 from ../src/addresstype.h:9,
34 from ../src/outputtype.h:9,
35 from ../src/script/descriptor.h:8,
36 from ../src/script/descriptor.cpp:5:
37../src/musig.h:17:108: in ‘constexpr’ expansion of ‘std::span<const unsigned char>(util::hex_literals::operator""_hex_u8<util::detail::Hex<65>{std::array<std::byte, 32>{std::__array_traits<std::byte, 32>::_Type{(std::byte)134, (std::byte)128, (std::byte)135, (std::byte)202, (std::byte)2, (std::byte)166, (std::byte)249, (std::byte)116, (std::byte)196, (std::byte)89, (std::byte)137, (std::byte)36, (std::byte)195, (std::byte)107, (std::byte)87, (std::byte)118, (std::byte)45, (std::byte)50, (std::byte)203, (std::byte)69, (std::byte)113, (std::byte)113, (std::byte)103, (std::byte)227, (std::byte)0, (std::byte)98, (std::byte)44, (std::byte)113, (std::byte)103, (std::byte)227, (std::byte)137, (std::byte)101}}}>())’
38/usr/include/c++/13/span:204:57: in ‘constexpr’ expansion of ‘((std::span<const unsigned char>*)this)->std::span<const unsigned char>::span<const unsigned char*>((& __arr)->std::array<unsigned char, 32>::data(), 32)’
39/usr/include/c++/13/span:167:4: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range<const unsigned char*>(__first, (__first + ((sizetype)__count)))’
40/usr/include/c++/13/debug/helper_functions.h:267:44: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (_Integral(), _Integral()))’
41/usr/include/c++/13/debug/helper_functions.h:197:44: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (std::__iterator_category<const unsigned char*>(__first), std::iterator_traits<const unsigned char*>::iterator_category()))’
42/usr/include/c++/13/debug/helper_functions.h:183:44: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (std::input_iterator_tag(), std::input_iterator_tag()))’
43/usr/include/c++/13/debug/helper_functions.h:143:20: error: ‘(((const unsigned char*)(&<anonymous>.std::array<unsigned char, 32>::_M_elems)) == 0)’ is not a constant expression
44 143 | { return __ptr == 0; }
45 | ~~~~~~^~~~
46ninja: build stopped: subcommand failed.