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

fmt formatting errors should be caught at build time, not at run time #262

Open
c-dilks opened this issue Jul 31, 2024 · 1 comment
Open

Comments

@c-dilks
Copy link
Member

c-dilks commented Jul 31, 2024

More recent versions of fmt can do this, but we may need to re-think how Logger is implemented, in particular:

fmt::print(
lev >= warn ? stderr : stdout,
fmt::runtime(fmt::format("{} {} {}\n", style(it->second), style(m_name), message)),
vals...);

@c-dilks
Copy link
Member Author

c-dilks commented Aug 12, 2024

This is somewhat more difficult than expected:

  • we are restricted to C++17, so to use fmt's compile-time error catching, we must use its FMT_STRING macro, which only accepts literals; as far as I understand, this means we need our own preprocessor macros. Note that things are easier in C++20
  • I tried writing such preoprocessor macro implementation in fix: catch bad fmt format strings at compile-time #267, but after some testing, it makes some generalized log printing rather difficult, and one-line if / else blocks become a bit dodgy (because of handling semicolons and scopes ({ and }))
  • We could use a better logging library, but I'm not sure it's a good idea on imposing yet another dependency just for logging; the Logger class exists to avoid another dependency

I'm going to leave this issue open, in case someone has a better idea than #267, or is willing to complete it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Unsorted
Development

Successfully merging a pull request may close this issue.

1 participant