aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Ehrlicher <Ch.Ehrlicher@gmx.de>2017-09-27 15:51:26 +0200
committerChristian Ehrlicher <Ch.Ehrlicher@gmx.de>2017-09-28 19:08:40 +0200
commitfa75c97e6f9b8d91df75d7a685e04eb0d213b229 (patch)
tree511c2c1329840adb2960f9952ff30710d8f3c4e8 /src
parentfd083b0811f87def47a57a86a72faf93ad2eb7b1 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/ContextUtils.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/ContextUtils.h b/src/ContextUtils.h
index ed00e25c..7783abe8 100644
--- a/src/ContextUtils.h
+++ b/src/ContextUtils.h
@@ -98,8 +98,8 @@ inline clang::NamespaceDecl *namespaceForType(clang::QualType q)
return nullptr;
q = TypeUtils::pointeeQualType(q);
- // Check if it's a class, struct or union
- clang::CXXRecordDecl *rec = q->getAsCXXRecordDecl();
+ // Check if it's a class, struct, union or enum
+ clang::TagDecl *rec = q->getAsTagDecl();
if (rec)
return namespaceForDecl(rec);