diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b262241..e8232dd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ ## v1.2.0 * Linking and including an external version of `fmt` is now supported. See TweakMe.h -* Fix compiler warnings when using clang's -Wdocumentation. Fixes [#12](https://github.com/odygrd/quill/issues/12). +* Fixed compiler warnings when using clang's -Wdocumentation. Fixes [#12](https://github.com/odygrd/quill/issues/12). +* Fixed a bug that wouldn't report a compile-time error for invalid format strings. Fixes [#13](https://github.com/odygrd/quill/issues/13). + ## v1.1.0 * Daily file handler. The file handler rollover every 24 hours * Rotating file handler. The file handler will rollover based on the size of the file diff --git a/quill/quill/include/quill/detail/LogMacros.h b/quill/quill/include/quill/detail/LogMacros.h index 69d249f5..71b7df2b 100644 --- a/quill/quill/include/quill/detail/LogMacros.h +++ b/quill/quill/include/quill/detail/LogMacros.h @@ -7,8 +7,8 @@ #include "quill/detail/misc/Common.h" -#include "quill/Logger.h" #include "quill/Fmt.h" +#include "quill/Logger.h" #include "quill/detail/misc/Macros.h" // Config Options @@ -22,12 +22,21 @@ #define QUILL_LOG_LEVEL_CRITICAL 7 #define QUILL_LOG_LEVEL_NONE 8 +/** + * Check in compile time the correctness of a format string + */ +template > +constexpr void check_format(const S& format_str, Args&&...) +{ + fmt::internal::check_format_string...>(format_str); +} + // Main Log Macros // clang-format off -#define QUILL_LOGGER_CALL(logger, log_statement_level, fmt, ...) do { \ - FMT_STRING(fmt); \ +#define QUILL_LOGGER_CALL(logger, log_statement_level, fmt, ...) do { \ + check_format(FMT_STRING(fmt), ##__VA_ARGS__); \ static constexpr quill::detail::StaticLogRecordInfo log_line_info{QUILL_STRINGIFY(__LINE__), __FILE__, __FUNCTION__, fmt, log_statement_level}; \ - logger->log(&log_line_info, ##__VA_ARGS__); \ + logger->log(&log_line_info, ##__VA_ARGS__); \ } while (0) // clang-format on