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

Remove fallback to inline specifier from FMT_CONSTEXPR(20) macro #2075

Merged

Conversation

alexezeder
Copy link
Contributor

@alexezeder alexezeder commented Dec 24, 2020

As it was discussed here - #2056 (comment), an fallback to the inline inside FMT_CONSTEXPR(20) macro definitions is not always a good solution. Especially when FMT_CONSTEXPR(20) macro should be used together with FMT_INLINE macro, in C++11 they both expand to inline specifier.

In this PR I removed that fallback to inline and placed inline specifiers where it's needed (for non-template, not member or friend defined in class/struct/union functions), so everything should stay the same in C++11. When FMT_CONSTEXPR(20) is expanded to constexpr all these manually-tuned functions will have constexpr inline specifiers, which is okay.

@alexezeder alexezeder force-pushed the fix/remove_inline_from_constexpr_macro branch from 70ae54a to f5e9b86 Compare December 27, 2020 05:08
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Mostly looks good, just a few minor comments inline =).

template <> FMT_CONSTEXPR const char* get_units<std::peta>() { return "Ps"; }
template <> FMT_CONSTEXPR const char* get_units<std::exa>() { return "Es"; }
template <> FMT_CONSTEXPR const char* get_units<std::ratio<60>>() {
template <> FMT_CONSTEXPR inline const char* get_units<std::atto>() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove inline from all these functions? Ideally all of this should be rewritten without template specializations but this is out of scope of the current PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It causes multiple definitions of these functions.
Maybe a test for multiple definitions can be added, which would include all headers in two object files and link them together. Because now I have to include chrono.h into util.h in the test directory to get this error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I don't think the multiple definition test is necessary.

test/format-test.cc Outdated Show resolved Hide resolved
test/format-test.cc Outdated Show resolved Hide resolved
@alexezeder alexezeder requested a review from vitaut December 30, 2020 06:12
@vitaut vitaut merged commit cdc5ef6 into fmtlib:master Dec 30, 2020
@alexezeder alexezeder deleted the fix/remove_inline_from_constexpr_macro branch January 15, 2021 21:16
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.

2 participants