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

Ahead of time validation of format strings #467

Closed
netheril96 opened this issue Feb 6, 2017 · 2 comments
Closed

Ahead of time validation of format strings #467

netheril96 opened this issue Feb 6, 2017 · 2 comments

Comments

@netheril96
Copy link

@netheril96 netheril96 commented Feb 6, 2017

One problem I encounters with fmt is that the validation of format strings is deferred to runtime, while in GCC and Clang snprintf is checked at compile time (when the format string is a literal). When I use fmt for logging errors, I get a formatting error instead because I missed an argument.

I would like to see an macro that in debug mode expands to a fmt::print followed by a global registration. Then I can run a checkAll() or similar methods from this global registration that validates all of the format strings and argument types in my program without waiting for the execution path to reach them.

@vitaut
Copy link
Contributor

@vitaut vitaut commented Feb 6, 2017

I am not sure if it is possible to write such macro. However, for printf-style formatting you can enable a compile-time check with a simple trick described in #62 (comment).

@vitaut vitaut closed this Feb 6, 2017
@vitaut
Copy link
Contributor

@vitaut vitaut commented Nov 6, 2017

Compile-time format string checks are now available: http://zverovich.net/2017/11/05/compile-time-format-strings.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants