llvm / llvm/llvm-project

[clang-tidy] bugprone-reserved-identifier will not emit a diagnostic for declarations if the identifier is used in an invoked macro

Open
#205,783 4 comments 0 reactions 0 assignees View on GitHub
clang-tidy false-negative
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The bugprone-reserved-identifier check is supposed to identify declarations which use names reserved by the C/C++ standard.

E.g.:

```c++
// declarations for which I would expect diagnostics from bugprone-reserved-identifier
void __foo() {}
int __x{};
```

That works for the most part, but if those symbols are used inside an invoked macro, then bugprone-reserved-identifier won't report them at all.
I would understand if it would report them, but not provide a FixIt.

To reproduce ([godbolt](https://godbolt.org/z/3c36G3qxj)):

```c++
void __foo() {}
void __bar() {}

int __x{};
int __y{};

#define FOO __foo
#define BAR __bar
#define X __x

int main() {
__foo();
BAR();

return X;
}
```

```bash
clang-tidy --checks="-*,bugprone-reserved-identifier" test.cpp
```

For `__foo` and `__y`, diagnostics are emitted, but not for `__bar` and `__x`.

Contributor guide

Open the contributing guide

Research direction

Start with the bugprone-reserved-identifier check and reproduce the issue using the provided test.cpp example and clang-tidy command. Trace why declarations referenced through invoked macros are skipped; done means diagnostics are emitted for __bar and __x as well as the directly used reserved identifiers, with any existing FixIt behavior preserved unless the tests require otherwise.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.