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

🐛 Cannot call non-constexpr function in constexpr context #2010

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

jgopel
Copy link
Contributor

@jgopel jgopel commented Nov 11, 2020

Problem:

  • gcc-8 gives the following error when compiling this function on all
    standards:
    test/std-format-test.cc: In member function 'constexpr auto std::formatter<S>::parse(std::format_parse_context&)':
    test/std-format-test.cc:112:17: error: call to non-'constexpr' function 'int isdigit(int)'
        if (!isdigit(c) || (++iter, get_char()) != '}')
         ~~~~~~~^~~

Solution:

  • Write a constexpr version of isdigit for use in this function.

I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.

@foonathan
Copy link
Contributor

I think a better solution would be to use '0' <= c <= '9' instead, which can keep it constexpr.

Problem:
- gcc-8 gives the following error when compiling this function on all
  standards:
    test/std-format-test.cc: In member function 'constexpr auto std::formatter<S>::parse(std::format_parse_context&)':
    test/std-format-test.cc:112:17: error: call to non-'constexpr' function 'int isdigit(int)'
        if (!isdigit(c) || (++iter, get_char()) != '}')
         ~~~~~~~^~~

Solution:
- Write a `constexpr` version of `isdigit` for use in this function.
@vitaut vitaut merged commit aa9b09a into fmtlib:master Nov 12, 2020
@vitaut
Copy link
Contributor

vitaut commented Nov 12, 2020

Thanks

@jgopel jgopel deleted the fix-incorrect-constexpr branch November 14, 2020 20:39
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.

3 participants