Fix: Resolve IntelliSense/linter false positive for type_is_unformattable_for #4634
+5
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Resolve IntelliSense/linter false positive for
type_is_unformattable_forProblem
The
type_is_unformattable_forstruct is intentionally left undefined to trigger compile-time errors when attempting to format types without formatters. However, this causes false positive errors in IDEs like VS Code that use IntelliSense or clangd, which flag the undefined struct as an error.Impact
Example
In VS Code, when opening a project using fmt (or spdlog which bundles fmt), the file tree shows a red dot on the submodule/folder containing
base.h, indicating errors even though the code compiles successfully.Solution
Make
type_is_unformattable_fora complete (but empty) struct definition instead of leaving it undefined. Replace the variable declaration with a type alias and add astatic_assertto maintain the compile-time error behavior.Changes
Before:
After:
The
static_assert(sizeof(T) != sizeof(T), ...)always evaluates to false, ensuring a compile-time error while the struct definition satisfies the linter.Benefits
static_assertand type alias still trigger appropriate errors when unformattable types are usedstatic_assertprovides a clear, actionable error messageTesting
Files Changed
include/fmt/base.h(lines ~2150 and ~2314)Related
This issue affects any project using fmt (or libraries that bundle fmt like spdlog) when viewed in VS Code or other IDEs with IntelliSense/clangd support.