[clang-tools-extra] [clang-tidy] Only expand <inttypes.h> macros in modernize-use-std-format/print (PR #97911)
Mike Crowe via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 14 10:56:03 PDT 2024
mikecrowe wrote:
> Unfortunately, walking the format string looking for macros also seems to match a macro that encloses the whole function invocation. This results in the check failing to work on expressions inside Catch2 `REQUIRE` macros for example.
>
> My new test case (that currently fails) is:
>
> ```c++
> #define SURROUND(x) x
> SURROUND(printf("Surrounding macro %d\n", 42));
> // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
> // CHECK-FIXES: std::print("Surrounding macro {}", 42);
> ```
>
> I'll try to fix this, but any advice is gratefully received.
I've pushed a new commit that works for the Lit test cases that I've added by getting the macro name for the function call and permitting that macro for the format string too. I can't say that I'm particularly happy with it, and there may be corner cases such as the same macro being intentionally used in both places, but it's the best I can currently work out how to do.
https://github.com/llvm/llvm-project/pull/97911
More information about the cfe-commits
mailing list