Diffusion Clazy fa75c97e6f9b

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

Authored by chehrlic on Sep 27 2017, 1:51 PM.

Description

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

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

Reviewers: smartins

Reviewed By: smartins

Subscribers: chehrlic

Differential Revision: https://phabricator.kde.org/D8010

Details