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

Replace use of newer C++ library feature with older equivalent #3638

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

qimiko
Copy link
Contributor

@qimiko qimiko commented Sep 14, 2023

When compiling something like the following bit of code:

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

int main() {
  fmt::format(FMT_STRING("hi {}\n"), 44);
  return 0;
}

on an environment that uses the older C++11 standard library with C++17 language features enabled, you get this error (significantly shortened):

.../include/fmt/core.h:2544:22: error: no template named 'is_default_constructible_v' in namespace 'std'; did you mean 'is_default_constructible'? [clang-diagnostic-error]
  if constexpr (std::is_default_constructible_v<
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                     is_default_constructible
.../include/type_traits:848:12: note: 'is_default_constructible' declared here
    struct is_default_constructible
           ^

The error comes from the usage of std::is_default_constructible_v, a template that was not added until C++17. This usage is gated by a check for __cpp_if_constexpr, another C++17 feature, but the compiler I am using does have support for if constexpr and defines the macro.
Unfortunately, having modern C++ features like if constexpr does not imply that a modern C++ standard library is available.

This replacement fixes the error for me and has equivalent behavior to the previous code. Judging by the surrounding bits of code, a standard library version of at least C++11 was already assumed so this is hopefully all good.

@vitaut vitaut merged commit 571a9b7 into fmtlib:master Sep 16, 2023
40 checks passed
@vitaut
Copy link
Contributor

vitaut commented Sep 16, 2023

Thank you

ckerr pushed a commit to transmission/fmt that referenced this pull request Nov 7, 2023
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.

None yet

2 participants