Conversation
vitaut
left a comment
There was a problem hiding this comment.
Thanks for the PR! One minor comment inline, otherwise LGTM.
test/compile-test.cc
Outdated
| static FMT_CONSTEXPR20 size_t s1 = fmt::formatted_size(FMT_COMPILE("{0}"), 42); | ||
| EXPECT_EQ(2, s1); | ||
| static FMT_CONSTEXPR20 size_t s2 = fmt::formatted_size(FMT_COMPILE("{0:<4.2f}"), 42.0); | ||
| EXPECT_EQ(5, s2); |
There was a problem hiding this comment.
static seems unnecessary, please remove.
|
Seems Clang-11 has some issue with memcpy not being constexpr. Trying to repro but for me clang 11 actually crashes... |
|
OK got a repro. I was missing that I needed to use libc++. Will investigate. |
|
Seems the problem is here: https://github.com/fmtlib/fmt/blob/master/include/fmt/format.h#L295-L305 I think Clang 11 supports -std=c++20, but the included libc++ doesn't have __cpp_lib_bit_cast, so we end up trying to use memcpy in a constexpr function. |
|
Maybe I can work around this by using __builtin_bit_cast |
|
For C++20 constexpr fmt needs a I suggest checking these conditions or @marksantaniello, You can enable Github Actions for your fmt fork |
Are you saying that there's a way to get all the same test workflows running on my fork? |
|
@marksantaniello |
|
Thanks. I'll have to figure do that if I make PRs in the future. The test matrix is pretty large. Anyway, it looks like the current version using __builtin_bit_cast is passing the checks. |
|
Current test matrix does not check: |
|
Ah, OK. Maybe I should figure out the workflows now then. I enabled "Actions" but I'm not sure how to clone the checks from here. And then I guess I'd need to add at least two more? |
|
Strategies are defined in the .github/workflows/linux.yml file: fmt/.github/workflows/linux.yml Lines 11 to 61 in 8bd02e9 I think for the test you need to add: |
|
|
test/compile-test.cc
Outdated
| TEST(compile_test, formatted_size) { | ||
| EXPECT_EQ(2, fmt::formatted_size(FMT_COMPILE("{0}"), 42)); | ||
| EXPECT_EQ(5, fmt::formatted_size(FMT_COMPILE("{0:<4.2f}"), 42.0)); | ||
| #ifdef __cpp_lib_bit_cast | ||
| FMT_CONSTEXPR20 | ||
| #endif | ||
| size_t s1 = fmt::formatted_size(FMT_COMPILE("{0}"), 42); | ||
| EXPECT_EQ(2, s1); | ||
| #ifdef __cpp_lib_bit_cast | ||
| FMT_CONSTEXPR20 | ||
| #endif | ||
| size_t s2 = fmt::formatted_size(FMT_COMPILE("{0:<4.2f}"), 42.0); | ||
| EXPECT_EQ(5, s2); | ||
| } |
There was a problem hiding this comment.
Let's conditionally compile the test case itself because the whole purpose of it is to test constexpr formatted_size. Also formatted_size -> contexpr_formatted_size to make it clear what we are testing here.
#ifdef __cpp_lib_bit_cast
TEST(compile_test, constexpr_formatted_size) {
FMT_CONSTEXPR20 size_t s1 = fmt::formatted_size(FMT_COMPILE("{0}"), 42);
EXPECT_EQ(2, s1);
FMT_CONSTEXPR20 size_t s2 = fmt::formatted_size(FMT_COMPILE("{0:<4.2f}"), 42.0);
EXPECT_EQ(5, s2);
}
#endif
.github/workflows/linux.yml
Outdated
| - cxx: g++-9 | ||
| build_type: Debug | ||
| std: 20 | ||
| install: sudo apt install g++-9 | ||
| os: ubuntu-18.04 | ||
| - cxx: g++-10 | ||
| build_type: Debug | ||
| std: 17 | ||
| os: ubuntu-18.04 | ||
| - cxx: g++-10 | ||
| build_type: Debug | ||
| std: 20 | ||
| os: ubuntu-18.04 |
There was a problem hiding this comment.
As commented earlier, let's not add new CI configs.
There was a problem hiding this comment.
Sorry, yes -- I'm just crap at git. Will try again.
|
Looks good but there are some merge conflicts, please rebase. |
|
Thanks! |
This reverts commit fd93b63.
Minimal changes to make fmt::formatted_size constexpr in C++20. Adjust the existing unit test accordingly.