Skip to content

Fix builds with GCC 11 and C++20

Juan Miguel Carceller requested to merge jcarcell/Gaudi:chrono into master

When building with GCC 11 and C++20 the following error message appears:

In file included from /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/format.hpp:49,
                 from /tmp/root/spack-stage/spack-stage-gaudi-37.1-hho4zispnivdpb7syohpmbpqpwaosdpu/spack-src/GaudiKernel/include/Gaudi/Accumulators.h:207,
                 from /tmp/root/spack-stage/spack-stage-gaudi-37.1-hho4zispnivdpb7syohpmbpqpwaosdpu/spack-src/GaudiKernel/tests/src/CountersUnitTest.cpp:15:
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/format/feed_args.hpp: In instantiation of 'void boost::io::detail::put_last(std::basic_ostream<_CharT, _Traits>&, const T&) [with Ch = char; Tr = std::char_traits<char>; T = std::chrono::duration<long int, std::ratio<1, 1000> >]':
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/format/feed_args.hpp:126:17:   required from 'void boost::io::detail::call_put_last(std::basic_ostream<_CharT, _Traits>&, const void*) [with Ch = char; Tr = std::char_traits<char>; T = const std::chrono::duration<long int, std::ratio<1, 1000> >]'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/format/feed_args.hpp:135:13:   required from 'boost::io::detail::put_holder<Ch, Tr>::put_holder(T&) [with T = const std::chrono::duration<long int, std::ratio<1, 1000> >; Ch = char; Tr = std::char_traits<char>]'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/format/feed_args.hpp:313:74:   required from 'boost::basic_format<Ch, Tr, Alloc>& boost::io::detail::feed(boost::basic_format<Ch, Tr, Alloc>&, T) [with Ch = char; Tr = std::char_traits<char>; Alloc = std::allocator<char>; T = const std::chrono::duration<long int, std::ratio<1, 1000> >&]'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/format/format_class.hpp:64:66:   required from 'boost::basic_format<Ch, Tr, Alloc>& boost::basic_format<Ch, Tr, Alloc>::operator%(const T&) [with T = std::chrono::duration<long int, std::ratio<1, 1000> >; Ch = char; Tr = std::char_traits<char>; Alloc = std::allocator<char>]'
/tmp/root/spack-stage/spack-stage-gaudi-37.1-hho4zispnivdpb7syohpmbpqpwaosdpu/spack-src/GaudiKernel/include/Gaudi/Accumulators.h:1040:59:   required from 'stream& Gaudi::Accumulators::StatCounter<Arithmetic, Atomicity>::printImpl(stream&, bool) const [with stream = std::basic_ostream<char>; Arithmetic = std::chrono::duration<long int, std::ratio<1, 1000> >; Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full]'
/tmp/root/spack-stage/spack-stage-gaudi-37.1-hho4zispnivdpb7syohpmbpqpwaosdpu/spack-src/GaudiKernel/include/Gaudi/Accumulators.h:1045:23:   required from 'std::ostream& Gaudi::Accumulators::StatCounter<Arithmetic, Atomicity>::print(std::ostream&, bool) const [with Arithmetic = std::chrono::duration<long int, std::ratio<1, 1000> >; Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full; std::ostream = std::basic_ostream<char>]'
/tmp/root/spack-stage/spack-stage-gaudi-37.1-hho4zispnivdpb7syohpmbpqpwaosdpu/spack-src/GaudiKernel/include/Gaudi/Accumulators.h:1044:19:   required from here
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/format/feed_args.hpp:99:12: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'const std::chrono::duration<long int, std::ratio<1, 1000> >')
   99 |         os << x ;
      |         ~~~^~~~
In file included from /usr/include/c++/11/iostream:39,
                 from /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/test/tools/detail/print_helper.hpp:31,
                 from /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/test/utils/lazy_ostream.hpp:16,
                 from /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/test/tools/context.hpp:19,
                 from /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/test/test_tools.hpp:42,
                 from /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-5uk4a2/include/boost/test/unit_test.hpp:18,
                 from /tmp/root/spack-stage/spack-stage-gaudi-37.1-hho4zispnivdpb7syohpmbpqpwaosdpu/spack-src/GaudiKernel/tests/src/CountersUnitTest.cpp:13:

The issue seems to be that for GCC 11 (and C++20, this doesn't seem to fail with C++17, why?) operator<< for std::chrono::duration is not found by boost. I was able to reproduce this problem on Ubuntu 22.04 and AlmaLinux 9 using the system compilers, 11.3.1 for Alma 9 (it also doesn't work on lxplus with 11.4.1) and 11.4.0 for Ubuntu 22.04. This PR fixes it by implementing a few suffixes that are enough for the current tests (since this is a sort of workaround I didn't want to implement all, alternatively I can copy the implementation in a newer libstdc++). In particular, the test test_Counters (ctest -R test_Counters) is directly affected by this and is passing.

The second change (fmt::runtime) is to disable compile checks since it will complain about json_fmt_args not having a constexpr destructor:

In file included from /root/Gaudi/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp:18:
/root/Gaudi/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp: In instantiation of 'Stream& {anonymous}::printCounter(Stream&, std::string_view, const json&) [with Stream = MsgStream; std::string_view = std::basic_string_view<char>; nlohmann::json_abi_v3_11_2::json = nlohmann::json_abi_v3_11_2::basic_json<>]':
/root/Gaudi/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp:207:21:   required from 'Gaudi::Monitoring::MessageSvcSink::flush(bool)::<lambda(auto:60&)> [with auto:60 = std::pair<const std::__cxx11::basic_string<char>, nlohmann::json_abi_v3_11_2::basic_json<> >]'
/usr/include/c++/11/bits/stl_algo.h:3820:5:   required from 'constexpr _Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::json_abi_v3_11_2::basic_json<> > >; _Funct = Gaudi::Monitoring::MessageSvcSink::flush(bool)::<lambda(auto:60&)>]'
/root/Gaudi/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp:209:8:   required from here
/root/Gaudi/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp:158:30:   in 'constexpr' expansion of 'fmt::v10::basic_format_string<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>(" |{}{:48}|{} |")'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/fmt/10.2.1-isqpse/include/fmt/core.h:2787:40:   in 'constexpr' expansion of 'fmt::v10::detail::parse_format_string<true, char, fmt::v10::detail::format_string_checker<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg> >(((fmt::v10::basic_format_string<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>*)this)->fmt::v10::basic_format_string<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>::str_, fmt::v10::detail::format_string_checker<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>(fmt::v10::basic_string_view<char>(((const char*)s))))'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/fmt/10.2.1-isqpse/include/fmt/core.h:2534:44:   in 'constexpr' expansion of 'fmt::v10::detail::parse_replacement_field<char, fmt::v10::detail::format_string_checker<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>&>((p + -1), end, (* & handler))'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/fmt/10.2.1-isqpse/include/fmt/core.h:2502:33:   in 'constexpr' expansion of '(& handler)->fmt::v10::detail::format_string_checker<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>::on_replacement_field((& handler)->fmt::v10::detail::format_string_checker<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>::on_arg_id(), begin)'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/fmt/10.2.1-isqpse/include/fmt/core.h:2677:20:   in 'constexpr' expansion of '((fmt::v10::detail::format_string_checker<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>*)this)->fmt::v10::detail::format_string_checker<char, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, {anonymous}::json_fmt_arg>::on_format_specs(id, begin, begin)'
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/fmt/10.2.1-isqpse/include/fmt/core.h:2684:51: error: 'constexpr decltype (ctx.begin()) fmt::v10::detail::parse_format_specs(ParseContext&) [with T = {anonymous}::json_fmt_arg; ParseContext = fmt::v10::detail::compile_parse_context<char>; decltype (ctx.begin()) = const char*]' called in a constant expression
 2684 |     return id >= 0 && id < num_args ? parse_funcs_[id](context_) : begin;
      |                                       ~~~~~~~~~~~~^
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/fmt/10.2.1-isqpse/include/fmt/core.h:2580:20: note: 'constexpr decltype (ctx.begin()) fmt::v10::detail::parse_format_specs(ParseContext&) [with T = {anonymous}::json_fmt_arg; ParseContext = fmt::v10::detail::compile_parse_context<char>; decltype (ctx.begin()) = const char*]' is not usable as a 'constexpr' function because:
 2580 | FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
      |                    ^~~~~~~~~~~~~~~~~~
/cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-01-09/x86_64-almalinux9-gcc11.3.1-opt/fmt/10.2.1-isqpse/include/fmt/core.h:2591:12: error: temporary of non-literal type 'fmt::v10::formatter<{anonymous}::json_fmt_arg>' in a constant expression
 2591 |     return formatter<mapped_type, char_type>().parse(ctx);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/root/Gaudi/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp:75:12: note: 'fmt::v10::formatter<{anonymous}::json_fmt_arg>' is not literal because:
   75 | class fmt::formatter<json_fmt_arg> {
      |            ^~~~~~~~~~~~~~~~~~~~~~~
/root/Gaudi/GaudiCoreSvc/src/MessageSvc/MessageSvcSink.cpp:75:12: note:   'fmt::v10::formatter<{anonymous}::json_fmt_arg>' does not have 'constexpr' destructor
Edited by Juan Miguel Carceller

Merge request reports