llvm / llvm/llvm-project

clang-tidy bugprone-argument-comment interaction with preprocessor macros / #define

Open
#173,042 1 comment 0 reactions 0 assignees View on GitHub
clang-tidy
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

An example like the following currently produces a warning with `bugprone-argument-comment` but most users should be surprised by this:

```
$ cat test.cpp
extern void print(const char *string);
#define LOG(message) print(/*string=*/message)
int main() {
LOG(/*message=*/"Hello World");
}

$ clang-tidy -checks=bugprone-argument-comment ./test.cpp
...
/home/matthiasb/test.cpp:4:7: warning: argument name 'message' in comment does not match parameter name 'string' [bugprone-argument-comment]
4 | LOG(/*message=*/"Hello World");
| ^
/home/matthiasb/test.cpp:1:31: note: 'string' declared here
1 | extern void print(const char *string);
| ^
```

Would be neat if it could match for the macro parameter names instead of the parameter names after substitution...

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the warning with the test.cpp example and the clang-tidy bugprone-argument-comment check. Trace how the check handles the LOG macro invocation and compare its behavior with the macro parameter names; done means the example no longer reports a false mismatch while ordinary argument comments remain checked.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.