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

[Clang-tidy] Why is there no warning when I use the redundant-declaration option?

Open Zhenhang1213 opened this issue 2 years ago • 4 comments

When I declare two variables, there is no warning. When I extern, there is a warning. This is different from gcc. Is this some kind of special consideration?

https://godbolt.org/z/9rePocxo3

Zhenhang1213 avatar Jul 31 '24 02:07 Zhenhang1213

Because check is for declarations, and "int x" is a definition. And definitions are explicitly excluded in check.

PiotrZSL avatar Aug 01 '24 16:08 PiotrZSL

Because check is for declarations, and "int x" is a definition. And definitions are explicitly excluded in check.

Why does the GCC have check?

Zhenhang1213 avatar Aug 02 '24 02:08 Zhenhang1213

Because check is for declarations, and "int x" is a definition. And definitions are explicitly excluded in check.

Why does the GCC have check?

Well, in theory every definition is also a declaration. But that's more a question to GCC devs. For me this check should be implemented as an compiler warning to match GCC, but initial idea were to match only declarations.

PiotrZSL avatar Aug 02 '24 08:08 PiotrZSL

Because check is for declarations, and "int x" is a definition. And definitions are explicitly excluded in check.

Why does the GCC have check?

Well, in theory every definition is also a declaration. But that's more a question to GCC devs. For me this check should be implemented as an compiler warning to match GCC, but initial idea were to match only declarations.

I think you are right

Zhenhang1213 avatar Aug 05 '24 01:08 Zhenhang1213