llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

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

Open PWVEC opened this issue 5 months ago • 4 comments

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

E.g.:

// 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):

void __foo() {}
void __bar() {}

int __x{};
int __y{};

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

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

    return X;
}
clang-tidy --checks="-*,bugprone-reserved-identifier" test.cpp

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

PWVEC avatar Jun 25 '26 11:06 PWVEC

@llvm/issue-subscribers-clang-tidy

Author: PWVEC

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

E.g.:

// 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):

void __foo() {}
void __bar() {}

int __x{};
int __y{};

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

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

    return X;
}
clang-tidy --checks=-*,bugprone-reserved-identifier" test.cpp

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

Hi, I would like to work on this issue. Could you assign it to me? Thanks.

ChrisLee02 avatar Aug 29 '26 04:08 ChrisLee02

https://godbolt.org/z/o8fT16eEP

vbvictor avatar Sep 03 '26 12:09 vbvictor

Hi, I would like to work on this issue. Could you assign it to me? Thanks.

Just post a PR when ready

vbvictor avatar Sep 03 '26 12:09 vbvictor