[cfe-dev] clang-tidy: readability-redundant-declaration assertion failure

Miklos Vajna via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 22 13:45:29 PST 2016


Hi Daniel,

Sorry, I just found one more problem with this check. ;-)

test.cpp:

----
#include <iostream>

struct C {
  static int I;
};

int C::I;

int main() { std::cerr << C::I << std::endl; }
----

Then running clang-tidy on this:

----
$ clang-tidy -checks=readability-redundant-declaration test.cpp --
test.cpp:7:8: warning: redundant 'I' declaration [readability-redundant-declaration]
int C::I;
       ^
test.cpp:4:14: note: previously declared here
  static int I;
             ^
----

But test.cpp:7 is a definition, not a declaration, removing it would
lead to a linker error when compiling the file:

----
$ clang++ -o test test.cpp
/tmp/test-b30549.o: In function `main':
test.cpp:(.text+0x15): undefined reference to `C::I'
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)
----

Maybe it's the static that confuses the check?

Regards,

Miklos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161122/d8247c93/attachment.sig>


More information about the cfe-dev mailing list