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

consteval error with FreeBSD 13.1 and Clang13 #3032

Closed
phire opened this issue Aug 10, 2022 · 7 comments
Closed

consteval error with FreeBSD 13.1 and Clang13 #3032

phire opened this issue Aug 10, 2022 · 7 comments

Comments

@phire
Copy link

phire commented Aug 10, 2022

/usr/home/buildbot/freebsd/pr-freebsd-x64/build/Source/UnitTests/Common/BitFieldTest.cpp:234:27: error: call to consteval function 'fmt::basic_format_string<char, BitField<0, 64, unsigned long, unsigned long> &>::basic_format_string<char [7], 0>' is not a constant expression
    EXPECT_EQ(fmt::format("{:02x}", object.full_u64),
                          ^
/usr/home/buildbot/freebsd/pr-freebsd-x64/build/Source/UnitTests/Common/BitFieldTest.cpp:234:27: note: undefined constructor 'basic_format_string<char [7], 0>' cannot be used in a constant expression
/usr/home/buildbot/freebsd/pr-freebsd-x64/build/Externals/fmt/include/fmt/core.h:3115:28: note: declared here
  FMT_CONSTEVAL FMT_INLINE basic_format_string(const S& s) : str_(s) {
                           ^
/usr/home/buildbot/freebsd/pr-freebsd-x64/build/Source/UnitTests/Common/BitFieldTest.cpp:236:27: error: call to consteval function 'fmt::basic_format_string<char, BitField<0, 64, long, long> &>::basic_format_string<char [7], 0>' is not a constant expression
    EXPECT_EQ(fmt::format("{:02x}", object.full_s64),

I could try and make a minimal reproduction and/or test on master, but I don't have a freebsd system setup, and this is just #2455 again. If you need one, just ask.

Looks like last time you worked around this issue by disabling consteval for all AppleClang. But it seems the bug isn't in AppleClang, just when you have both Regular Clang and libc++. And now we have a second OS with libc++ plus a new enough version of Clang.

Our testing showed that upgrading to Clang14 fixed the issue. Also forcing FMT_CONSTEVAL off on FreeBSD + Clang13 fixed it dolphin-emu/dolphin#10973, which is the solution we will go with.

But maybe you should update master to check for _LIBCPP_VERSION instead of __apple_build_version__. Also, since this seems to be fixed in later versions of Clang, maybe you should limit that check to just Clang 13?

@mpiatka
Copy link

mpiatka commented Aug 10, 2022

I run into the same or similar issue on both GCC and clang on c++20. Reproduces on current master. Minimal reproduction:

#include <string_view>
#include <fmt/core.h>

extern int get_number();

template<typename... Args>
inline void log_msg(std::string_view msg, Args... args){
    fmt::print(msg, args...);
}

int main(){
    log_msg("{}\n", get_number());

    return 0;
}

compiler explorer link

@vitaut
Copy link
Contributor

vitaut commented Aug 10, 2022

@mpiatka, the error in your example is unrelated and expected because the format string should be known at compile time: https://fmt.dev/latest/api.html#core-api.

@vitaut
Copy link
Contributor

vitaut commented Aug 10, 2022

@phire, could you provide a repro (ideally on godbolt)?

@phire
Copy link
Author

phire commented Aug 10, 2022

Godbolt doesn't seem to have freebsd, but I'll download a VM and get you a repro.

@vitaut
Copy link
Contributor

vitaut commented Aug 21, 2022

But maybe you should update master to check for _LIBCPP_VERSION instead of apple_build_version.

I don't think it's a good idea because this config works on some systems, e.g. https://godbolt.org/z/rMcYPj66P.

@vitaut
Copy link
Contributor

vitaut commented Aug 21, 2022

I wasn't able to repro the issue on the following test case:

test.cc:

#include <fmt/core.h>

int main() {
  uint64_t full_u64;
  auto s = fmt::format("{:02x}", full_u64);
}
% uname -a
FreeBSD freebsd 13.1-RELEASE-p1 FreeBSD 13.1-RELEASE-p1 GENERIC amd64
% clang++ --version
FreeBSD clang version 13.0.0 ([email protected]:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: x86_64-unknown-freebsd13.1
Thread model: posix
InstalledDir: /usr/bin

Compile command: c++ -c test.cc -I include -std=c++20.

Please provide a self-contained repro.

@vitaut
Copy link
Contributor

vitaut commented Oct 1, 2022

Closing as I wasn't able to reproduce the issue in the described configuration. Feel free to reopen with more repro details.

@vitaut vitaut closed this as completed Oct 1, 2022
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

3 participants