| Issue |
160991
|
| Summary |
[clang-tidy] Peculiar behaviour of modernize-use-std-format
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
asakovets
|
Hi,
I’ve encountered unexpected behavior with the modernize-use-std-format check in clang-tidy. Consider the following code:
```cpp
#include <fmt/format.h>
namespace foo {
void info__ (const char * s, ...) {}
template <typename... Args>
void info_fmt (fmt::format_string<Args...> fmt, Args &&... args) {}
}
int main ()
{
foo::info__ ("hello, %s!", "world");
}
```
My `.clang-tidy` configuration is
```
Checks: 'modernize-use-std-format'
CheckOptions:
- key: modernize-use-std-format.StrFormatLikeFunctions
value: "foo::info"
- key: modernize-use-std-format.ReplacementFormatFunction
value: foo::info_fmt
```
Running clang-tidy:
```bash
clang-tidy -checks=-clang-analyzer-* fmt.cc
1 warning generated.
~/fmt.cc:12:5: warning: use 'foo::info_fmt' instead of 'info__' [modernize-use-std-format]
12 | foo::info__ ("hello, %s!", "world");
| ^~~~~~~~~~~ ~~~~~~~~~~~~
| foo::info_fmt"hello, {}!"
```
The warning suggests replacing `info__` with `info_fmt`, even though StrFormatLikeFunctions only includes `foo::info`—not `foo::info__`. It appears that clang-tidy matches function names by prefix rather than requiring an exact match.
After applying the suggested fix and running clang-tidy again, it then suggests replacing `foo::info_fmt` with `foo::info_fmt`, creating a “diagnostics loop”:
```bash
clang-tidy -checks=-clang-analyzer-* fmt.cc
1 warning generated.
~/fmt.cc:12:5: warning: use 'foo::info_fmt' instead of 'info_fmt' [modernize-use-std-format]
12 | foo::info_fmt ("hello, {}!", "world");
| ^~~~~~~~~~~~~ ~~~~~~~~~~~~
| foo::info_fmt "hello, {{}}!"
```
Is it intentional?
clang-tidy version: 21.1.2
Platform: Windows
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs