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

fmt::v8: bigint build failure with clang-10 #2490

Closed
jcelerier opened this issue Sep 7, 2021 · 8 comments · Fixed by #2491
Closed

fmt::v8: bigint build failure with clang-10 #2490

jcelerier opened this issue Sep 7, 2021 · 8 comments · Fixed by #2491

Comments

@jcelerier
Copy link
Contributor

#define FMT_HEADER_ONLY
#include <fmt/format.h>
int main() 
{
  fmt::detail::bigint b;
  b.square();
}

causes

In file included from /opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:2983:
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/format-inl.h:557:49: error: variable of non-literal type 'basic_memory_buffer<fmt::v8::detail::bigint::bigit, bigits_capacity>' (aka 'basic_memory_buffer<unsigned int, bigits_capacity>') cannot be defined in a constexpr function
    basic_memory_buffer<bigit, bigits_capacity> n(std::move(bigits_));
                                                ^
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:651:13: note: 'basic_memory_buffer<unsigned int, 32, std::allocator<unsigned int> >' is not literal because it has data member 'alloc_' of non-literal type 'std::allocator<unsigned int>'
  Allocator alloc_;
            ^

repro: https://godbolt.org/z/nT1TP4Wof ; maybe FMT_CONSTEXPR20 needs to start from clang-11 (where the above code compiles without issues)

@jcelerier
Copy link
Contributor Author

jcelerier commented Sep 7, 2021

e.g. something like

#if ((__cplusplus >= 202002L) && \
     (!FMT_CLANG_VERSION || FMT_CLANG_VERSION >= 1100)) || \
    (__cplusplus >= 201709L && FMT_GCC_VERSION >= 1002)
#  define FMT_CONSTEXPR20 constexpr
#else
#  define FMT_CONSTEXPR20
#endif

(can make a pr if you want and that sounds ok)

@alexezeder
Copy link
Contributor

alexezeder commented Sep 7, 2021

The error is actually caused by libstdc++ (GCC standard library) headers, not the Clang or libc++ (LLVM standard library) - https://godbolt.org/z/dbqre1TaW. So Clang 10 config has libstdc++ with major version 9, while Clang 11 config has major version 10. (thanks to @phprus for _GLIBCXX_RELEASE macro)

@phprus
Copy link
Contributor

phprus commented Sep 7, 2021

libstdc++ defined macro _GLIBCXX_RELEASE with major libstdc++ version.

@jcelerier
Copy link
Contributor Author

I think that the libstdc++ version comes from the gcc version installed on the docker image used, which is what clang will use by default ; what would be interesting is to see whether clang-10 with libstdc++-11 would work. hmm..

@jcelerier
Copy link
Contributor Author

jcelerier commented Sep 7, 2021

and indeed, g++-9 in -std=c++2a mode does define __cplusplus to 201709 so this case is not encountered with GCC, only with Clang ✕ libstdc++

@jcelerier
Copy link
Contributor Author

#if ((__cplusplus >= 202002L) && \
     (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE > 9)) || \
    (__cplusplus >= 201709L && FMT_GCC_VERSION >= 1002)
#  define FMT_CONSTEXPR20 constexpr
#else
#  define FMT_CONSTEXPR20
#endif

@vitaut
Copy link
Contributor

vitaut commented Sep 7, 2021

PR is welcome!

@alexezeder
Copy link
Contributor

#if ((__cplusplus >= 202002L) && \
     (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE > 9)) || \
    (__cplusplus >= 201709L && FMT_GCC_VERSION >= 1002)
#  define FMT_CONSTEXPR20 constexpr
#else
#  define FMT_CONSTEXPR20
#endif

Yeah, that should work - https://godbolt.org/z/vYP7MWfz9

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 a pull request may close this issue.

4 participants