Fix false warning in qhash-namespace check for enum (classes)
ClosedPublic

Authored by chehrlic on Sep 27 2017, 2:08 PM.

Details

Summary

When a qHash() function is defined for a enum class in a namespace, clazy wrongly prints the warning
'Move qHash(Foo::Bar) out of namespace Foo' because ContextUtils::namespaceForType() does not consider
enumerations. Therefore I changed QualType::getAsCXXRecorDecl() to QualType::getAsTagDec()
which returns the base class of RecordType and EnumType (and is the one which is passed to namespaceForDecl())

Type::getAsTagDecl() should be slightly faster since it avoids a dyna cast, don't know since when this function
is available though, at last it's in 4.0.0

version: clang version 4.0.1 (tags/RELEASE_401/final 305264)

Attn: there is also a change in main.cpp.expected since clang 4.0.0 prints qHash(IntFoo) instead the
expected qHash(NS::IntFoo) in the warning output ...

Test Plan
  • added enum class check to qhash-namespace unit test
  • run test without modification which fails with the additional warning +qhash-namespace/main.cpp:22:5: warning: Move qHash(NS::EnumClass) out of namespace NS [-Wclazy-qhash-namespace]
  • apply my modification, re-run unit test, no additional warnings

Diff Detail

Repository
R74 Clazy
Branch
qhash_enum_class
Lint
No Linters Available
Unit
No Unit Test Coverage
chehrlic created this revision.Sep 27 2017, 2:08 PM
smartins accepted this revision.Sep 27 2017, 7:54 PM

thanks

This revision is now accepted and ready to land.Sep 27 2017, 7:54 PM

Should go to master, as the check only exists there

chehrlic closed this revision.Sep 28 2017, 5:09 PM