Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC9 issue: static_assert(std::is_same<uint64_or_128_t<UInt>, UInt>::value, ""); #3803

Closed
Vertexwahn opened this issue Jan 11, 2024 · 7 comments

Comments

@Vertexwahn
Copy link
Contributor

Vertexwahn commented Jan 11, 2024

Commit fd87a23 gives me the following error using GCC9:

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from bazel-out/k8-fastbuild/bin/external/fmt~override/_virtual_includes/fmt/fmt/format-inl.h:25,
                 from external/fmt~override/src/format.cc:8:
bazel-out/k8-fastbuild/bin/external/fmt~override/_virtual_includes/fmt/fmt/format.h: In instantiation of 'OutputIt fmt::v10::detail::write_int(OutputIt, UInt, unsigned int, const fmt::v10::format_specs<Char>&, const fmt::v10::detail::digit_grouping<Char>&) [with OutputIt = fmt::v10::basic_appender<char>; UInt = __int128 unsigned; Char = char]':
bazel-out/k8-fastbuild/bin/external/fmt~override/_virtual_includes/fmt/fmt/format.h:2234:14:   required from 'bool fmt::v10::detail::loc_writer<Char>::operator()(T) [with T = __int128; typename std::enable_if<std::integral_constant<bool, (((fmt::v10::detail::is_integral<T>::value && (! std::is_same<T, bool>::value)) && (! std::is_same<T, char>::value)) && (! std::is_same<T, wchar_t>::value))>::value, int>::type <anonymous> = 0; Char = char]'
bazel-out/k8-fastbuild/bin/external/fmt~override/_virtual_includes/fmt/fmt/base.h:1677:17:   required from 'constexpr decltype (vis(0)) fmt::v10::basic_format_arg<Context>::visit(Visitor&&) [with Visitor = fmt::v10::detail::loc_writer<>&; Context = fmt::v10::context; decltype (vis(0)) = bool]'
bazel-out/k8-fastbuild/bin/external/fmt~override/_virtual_includes/fmt/fmt/format.h:1118:28:   required from 'decltype (vis(0)) fmt::v10::loc_value::visit(Visitor&&) [with Visitor = fmt::v10::detail::loc_writer<>; decltype (vis(0)) = bool]'
bazel-out/k8-fastbuild/bin/external/fmt~override/_virtual_includes/fmt/fmt/format-inl.h:143:78:   required from here
bazel-out/k8-fastbuild/bin/external/fmt~override/_virtual_includes/fmt/fmt/format.h:2141:60: error: static assertion failed
 2141 |   static_assert(std::is_same<uint64_or_128_t<UInt>, UInt>::value, "");

How to reproduce?

Use Ubuntu 20.04 + GCC9

Add hello.cpp file to fmt repo:

#include <iostream>
#include "fmt/core.h"

using namespace std;

int main(int argc, char *argv[]) {
  std::string name = "Julian";
  cout << fmt::format("Hello! {}", name) << std::endl;
  return 0;
}

Try to compile

g++ -std=c++2a -o hello hello.cpp format.cc os.cc
In file included from fmt/format-inl.h:25,
                 from format.cc:8:
fmt/format.h: In instantiation of ‘OutputIt fmt::v10::detail::write_int(OutputIt, UInt, unsigned int, const fmt::v10::format_specs<Char>&, const fmt::v10::detail::digit_grouping<Char>&) [with OutputIt = fmt::v10::basic_appender<char>; UInt = __int128 unsigned; Char = char]’:
fmt/format.h:2234:14:   required from ‘bool fmt::v10::detail::loc_writer<Char>::operator()(T) [with T = __int128; typename std::enable_if<std::integral_constant<bool, (((fmt::v10::detail::is_integral<T>::value && (! std::is_same<T, bool>::value)) && (! std::is_same<T, char>::value)) && (! std::is_same<T, wchar_t>::value))>::value, int>::type <anonymous> = 0; Char = char]’
fmt/base.h:1677:17:   required from ‘constexpr decltype (vis(0)) fmt::v10::basic_format_arg<Context>::visit(Visitor&&) [with Visitor = fmt::v10::detail::loc_writer<>&; Context = fmt::v10::context; decltype (vis(0)) = bool]’
fmt/format.h:1118:28:   required from ‘decltype (vis(0)) fmt::v10::loc_value::visit(Visitor&&) [with Visitor = fmt::v10::detail::loc_writer<>; decltype (vis(0)) = bool]’
fmt/format-inl.h:143:78:   required from here
fmt/format.h:2141:60: error: static assertion failed
 2141 |   static_assert(std::is_same<uint64_or_128_t<UInt>, UInt>::value, "");
      |                                                            ^~~~~
fmt/format.h: In instantiation of ‘constexpr OutputIt fmt::v10::detail::write_int(OutputIt, fmt::v10::detail::write_int_arg<T>, const fmt::v10::format_specs<Char>&, fmt::v10::detail::locale_ref) [with Char = char; OutputIt = fmt::v10::basic_appender<char>; T = __int128 unsigned]’:
fmt/format.h:2305:19:   required from ‘constexpr OutputIt fmt::v10::detail::write_int_noinline(OutputIt, fmt::v10::detail::write_int_arg<T>, const fmt::v10::format_specs<Char>&, fmt::v10::detail::locale_ref) [with Char = char; OutputIt = fmt::v10::basic_appender<char>; T = __int128 unsigned]’
fmt/format.h:2315:28:   required from ‘constexpr OutputIt fmt::v10::detail::write(OutputIt, T, const fmt::v10::format_specs<Char>&, fmt::v10::detail::locale_ref) [with Char = char; OutputIt = fmt::v10::basic_appender<char>; T = __int128; typename std::enable_if<((fmt::v10::detail::is_integral<T>::value && (! std::is_same<T, bool>::value)) && std::is_same<OutputIt, fmt::v10::basic_appender<T> >::value), int>::type <anonymous> = 0]’
fmt/format.h:3855:25:   required from ‘constexpr fmt::v10::detail::arg_formatter<Char>::iterator fmt::v10::detail::arg_formatter<Char>::operator()(T) [with T = __int128; Char = char; fmt::v10::detail::arg_formatter<Char>::iterator = fmt::v10::basic_appender<char>]’
fmt/base.h:1677:17:   required from ‘constexpr decltype (vis(0)) fmt::v10::basic_format_arg<Context>::visit(Visitor&&) [with Visitor = fmt::v10::detail::arg_formatter<char>; Context = fmt::v10::context; decltype (vis(0)) = fmt::v10::basic_appender<char>]’
fmt/format.h:4384:7:   required from ‘const Char* fmt::v10::detail::vformat_to(fmt::v10::detail::buffer<T>&, fmt::v10::basic_string_view<Char>, typename fmt::v10::detail::vformat_args<Char>::type, fmt::v10::detail::locale_ref)::format_handler::on_format_specs(int, const Char*, const Char*) [with Char = char]’
fmt/format.h:4390:3:   required from ‘void fmt::v10::detail::vformat_to(fmt::v10::detail::buffer<T>&, fmt::v10::basic_string_view<Char>, typename fmt::v10::detail::vformat_args<Char>::type, fmt::v10::detail::locale_ref) [with Char = char; typename fmt::v10::detail::vformat_args<Char>::type = fmt::v10::basic_format_args<fmt::v10::context>]’
format.cc:32:75:   required from here
fmt/format.h:2249:60: error: static assertion failed
 2249 |   static_assert(std::is_same<T, uint32_or_64_or_128_t<T>>::value, "");
      |                                                            ^~~~~

If it try on my Ubuntu 20.04 system:

gh repo clone fmtlib/fmt
cd fmt
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON \
              -DCMAKE_CXX_STANDARD=17 -DFMT_DOC=OFF \
              -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \
              -DFMT_PEDANTIC=ON -DFMT_WERROR=ON ..
cmake --build .

it works without any problems - still unclear what the difference is here

I do not have this issue with the latest release 10.2.1

@Vertexwahn Vertexwahn changed the title gcc9: error GCC9 issue: static_assert(std::is_same<uint64_or_128_t<UInt>, UInt>::value, ""); Jan 11, 2024
@Vertexwahn Vertexwahn reopened this Jan 11, 2024
@vitaut
Copy link
Contributor

vitaut commented Jan 11, 2024

Godbolt repro: https://www.godbolt.org/z/WGdTWKqaf

@vitaut
Copy link
Contributor

vitaut commented Jan 11, 2024

Commit that introduced the issue: 401f087.

@phprus
Copy link
Contributor

phprus commented Jan 11, 2024

GCC bug, fixed in GCC 10.3: gcc-mirror/gcc@8eb9a45

We need define num_bits<uint128_t>() and if uint128_t is not equal to uint128_fallback then define num_bits<uint128_fallback>().

@phprus
Copy link
Contributor

phprus commented Jan 11, 2024

Fix demo on Godbolt: https://www.godbolt.org/z/cGaMxvKxc

@rexainn
Copy link

rexainn commented Jan 12, 2024

So we should installed gcc 10+ to solve this problem?

@phprus
Copy link
Contributor

phprus commented Jan 12, 2024

gcc 10.3+ or use -std=gnu++2a (with gcc extensions) instead of -std=c++2a

@vitaut
Copy link
Contributor

vitaut commented Jan 12, 2024

Fixed in 0cdee90. Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants