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

copying an object of non-trivial type error #2970

Closed
wants to merge 1 commit into from

Conversation

federico-busato
Copy link
Contributor

The fix addresses the following error related to fmt-9.0.0 uint128_fallback, reproducible with GCC-8.3.0

fmt/format.h:290:12: error: 'void* memcpy(void*, const void*, size_t)' copying an object of non-trivial type 'class fmt::v9::detail::uint128_fallback' from an array of 'const long double' [-Werror=class-memaccess]
   std::memcpy(&to, &from, sizeof(to));
   ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fmt/format.h:309:7: note: 'class fmt::v9::detail::uint128_fallback' declared here
 class uint128_fallback {

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR but please revert unrelated changes.

@vitaut
Copy link
Contributor

vitaut commented Jul 6, 2022

Also could you post the full diagnostic to see where the problematic call comes from?

@federico-busato
Copy link
Contributor Author

you are right. Sorry, I messed up the commits.
This is the full log:

fmt/include/fmt/format.h: In instantiation of 'To fmt::v9::detail::bit_cast(const From&) [with To = fmt::v9::detail::uint128_fallback; From = long double; typename std::enable_if<(sizeof (To) == sizeof (From)), int>::type <anonymous> = 0]':
fmt/include/fmt/format.h:1395:75:   required from 'bool fmt::v9::detail::basic_fp<F>::assign(Float) [with Float = long double; typename std::enable_if<(! std::integral_constant<bool, (std::numeric_limits<Float>::digits == 106)>::value), int>::type <anonymous> = 0; F = fmt::v9::detail::uint128_fallback]'
fmt/include/fmt/format.h:3137:47:   required from 'int fmt::v9::detail::format_float(Float, int, fmt::v9::detail::float_specs, fmt::v9::detail::buffer<char>&) [with Float = long double]'
fmt/include/fmt/format.h:3205:23:   required from 'OutputIt fmt::v9::detail::write(OutputIt, T, fmt::v9::basic_format_specs<Char>, fmt::v9::detail::locale_ref) [with Char = char; OutputIt = fmt::v9::appender; T = long double; typename std::enable_if<std::integral_constant<bool, (std::is_floating_point<T>::value || std::is_same<T, void>::value)>::value, int>::type <anonymous> = 0]'
fmt/include/fmt/format.h:3369:21:   required from 'fmt::v9::detail::arg_formatter<Char>::iterator fmt::v9::detail::arg_formatter<Char>::operator()(T) [with T = long double; Char = char; fmt::v9::detail::arg_formatter<Char>::iterator = fmt::v9::appender]'
fmt/include/fmt/core.h:1637:11:   required from 'decltype (vis(0)) fmt::v9::visit_format_arg(Visitor&&, const fmt::v9::basic_format_arg<Context>&) [with Visitor = fmt::v9::detail::arg_formatter<char>&; Context = fmt::v9::basic_format_context<fmt::v9::appender, char>; decltype (vis(0)) = fmt::v9::appender]'
fmt/include/fmt/format.h:4107:38:   required from 'const Char* fmt::v9::detail::vformat_to(fmt::v9::detail::buffer<T>&, fmt::v9::basic_string_view<Char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<typename std::conditional<std::is_same<typename fmt::v9::type_identity<T>::type, char>::value, fmt::v9::appender, std::back_insert_iterator<fmt::v9::detail::buffer<typename fmt::v9::type_identity<T>::type> > >::type, typename fmt::v9::type_identity<T>::type> >, fmt::v9::detail::locale_ref)::format_handler::on_format_specs(int, const Char*, const Char*) [with Char = char]'
fmt/include/fmt/format.h:4110:1:   required from 'void fmt::v9::detail::vformat_to(fmt::v9::detail::buffer<T>&, fmt::v9::basic_string_view<Char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<typename std::conditional<std::is_same<typename fmt::v9::type_identity<T>::type, char>::value, fmt::v9::appender, std::back_insert_iterator<fmt::v9::detail::buffer<typename fmt::v9::type_identity<T>::type> > >::type, typename fmt::v9::type_identity<T>::type> >, fmt::v9::detail::locale_ref) [with Char = char; typename fmt::v9::type_identity<T>::type = char; typename std::conditional<std::is_same<typename fmt::v9::type_identity<T>::type, char>::value, fmt::v9::appender, std::back_insert_iterator<fmt::v9::detail::buffer<typename fmt::v9::type_identity<T>::type> > >::type = fmt::v9::appender]'
fmt/include/fmt/core.h:3179:19:   required from 'OutputIt fmt::v9::vformat_to(OutputIt, fmt::v9::string_view, fmt::v9::format_args) [with OutputIt = std::back_insert_iterator<fmt::v9::basic_memory_buffer<char, 2048> >; typename std::enable_if<fmt::v9::detail::is_output_iterator<OutputIt, char>::value, int>::type <anonymous> = 0; fmt::v9::string_view = fmt::v9::basic_string_view<char>; fmt::v9::format_args = fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char> >]'
fmt/include/fmt/core.h:3199:18:   required from 'OutputIt fmt::v9::format_to(OutputIt, fmt::v9::format_string<T ...>, T&& ...) [with OutputIt = std::back_insert_iterator<fmt::v9::basic_memory_buffer<char, 2048> >; T = {const tm&}; typename std::enable_if<fmt::v9::detail::is_output_iterator<OutputIt, char>::value, int>::type <anonymous> = 0; fmt::v9::format_string<T ...> = fmt::v9::basic_format_string<char, const tm&>]'
file.h:204:69:   required from here
fmt/include/fmt/format.h:290:12: error: 'void* memcpy(void*, const void*, size_t)' copying an object of non-trivial type 'class fmt::v9::detail::uint128_fallback' from an array of 'const long double' [-Werror=class-memaccess]
   std::memcpy(&to, &from, sizeof(to));
   ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fmt/format.h:309:7: note: 'class fmt::v9::detail::uint128_fallback' declared here
 class uint128_fallback {
       ^~~~~~~~~~~~~~~~

from: fmt::format_to(std::back_inserter(out), "[{:%Y-%m-%d %H:%M:%S}]", tm);, where tm is an instance of *std::tm

@phprus
Copy link
Contributor

phprus commented Jul 6, 2022

Please provide a reproduction code and compiler options.

On godbolt without error:
https://godbolt.org/z/bhGWxxcbh

@vitaut
Copy link
Contributor

vitaut commented Jul 6, 2022

One more thing: do you by any chance have a godbolt repro for this warning? I tried to make one in https://godbolt.org/z/7Ybn5zrr9 but to no avail.

@federico-busato
Copy link
Contributor Author

unfortunately, I cannot expose much as the code comes from an internal build pipeline. I also tried it on my side on the nearest configurations Arm64 GCC-8.5.0 and x86-64 GCC-8.3.0 and I'm not able to reproduce the error. Maybe it is an issue specifically related to Arm64 GCC-8.3-2019.03 Linux-GNU. If you think that this fix is not relevant, please discard it. I see that uint128_fallback is trivially copiable

@vitaut
Copy link
Contributor

vitaut commented Jul 6, 2022

If you think that this fix is not relevant, please discard it.

Yeah, considering that uint128_fallback is trivially copyable I don't think we should merge this in unless the warning reproduces more widely. But thanks anyway.

@vitaut vitaut closed this Jul 6, 2022
@vitaut
Copy link
Contributor

vitaut commented Jul 28, 2022

I ended up suppressing the warning since it appears to be more wide spread (see e.g. #3000).

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

Successfully merging this pull request may close these issues.

4 participants