diff options
-rw-r--r-- | Changelog | 1 | ||||
-rw-r--r-- | ClazySources.cmake | 1 | ||||
-rw-r--r-- | checks.json | 5 | ||||
-rw-r--r-- | src/ContextUtils.h | 46 | ||||
-rw-r--r-- | src/checks/level1/README-qhash-namespace.md | 4 | ||||
-rw-r--r-- | src/checks/level1/qhash-namespace.cpp | 68 | ||||
-rw-r--r-- | src/checks/level1/qhash-namespace.h | 39 | ||||
-rw-r--r-- | tests/clazy/test_requested_checks.sh.expected | 17 | ||||
-rw-r--r-- | tests/qhash-namespace/config.json | 7 | ||||
-rw-r--r-- | tests/qhash-namespace/main.cpp | 22 | ||||
-rw-r--r-- | tests/qhash-namespace/main.cpp.expected | 6 |
11 files changed, 208 insertions, 8 deletions
@@ -54,6 +54,7 @@ qproperty-without-notify virtual-signal overridden-signal + qhash-namespace - missing-qobject-macro is now a level2 check, instead of level1. Because, people can omit Q_OBJECT intentionally. - Added -only-qt option, which will make clazy bailout early on non-Qt files. diff --git a/ClazySources.cmake b/ClazySources.cmake index e6222cfe..b888beca 100644 --- a/ClazySources.cmake +++ b/ClazySources.cmake @@ -55,6 +55,7 @@ set(CLAZY_CHECKS_SRCS ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/post-event.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/incorrect-emit.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/overridden-signal.cpp + ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/qhash-namespace.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/virtual-signal.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/base-class-event.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/container-inside-loop.cpp diff --git a/checks.json b/checks.json index beee0b84..5525027c 100644 --- a/checks.json +++ b/checks.json @@ -256,6 +256,11 @@ "categories" : ["bug", "readability"] }, { + "name" : "qhash-namespace", + "level" : 1, + "categories" : ["bug"] + }, + { "name" : "base-class-event", "level" : 2, "categories" : ["bug"] diff --git a/src/ContextUtils.h b/src/ContextUtils.h index f195c6d7..ed00e25c 100644 --- a/src/ContextUtils.h +++ b/src/ContextUtils.h @@ -23,6 +23,7 @@ #define CLAZY_CONTEXT_UTILS_H #include "clazy_export.h" +#include "TypeUtils.h" #include <clang/AST/DeclBase.h> #include <clang/AST/Decl.h> @@ -75,6 +76,51 @@ inline clang::DeclContext * contextForDecl(clang::Decl *decl) return decl->getDeclContext(); } +inline clang::NamespaceDecl *namespaceForDecl(clang::Decl *decl) +{ + if (!decl) + return nullptr; + + clang::DeclContext *declContext = decl->getDeclContext(); + while (declContext) { + if (auto ns = llvm::dyn_cast<clang::NamespaceDecl>(declContext)) + return ns; + + declContext = declContext->getParent(); + } + + return nullptr; +} + +inline clang::NamespaceDecl *namespaceForType(clang::QualType q) +{ + if (q.isNull()) + return nullptr; + + q = TypeUtils::pointeeQualType(q); + // Check if it's a class, struct or union + clang::CXXRecordDecl *rec = q->getAsCXXRecordDecl(); + if (rec) + return namespaceForDecl(rec); + + // Or maybe it's a typedef to a builtin type: + auto typeDefType = q->getAs<clang::TypedefType>(); + if (typeDefType) { + clang::TypedefNameDecl* typedeff = typeDefType->getDecl(); + return namespaceForDecl(typedeff); + } + + return nullptr; +} + +inline clang::NamespaceDecl *namespaceForFunction(clang::FunctionDecl *func) +{ + if (auto ns = llvm::dyn_cast<clang::NamespaceDecl>(func->getDeclContext())) + return ns; + + return namespaceForDecl(func); +} + /** * Returns the first context of type T in which the specified context is in. * Contexts are namespaces, classes, inner classes, functions, etc. diff --git a/src/checks/level1/README-qhash-namespace.md b/src/checks/level1/README-qhash-namespace.md new file mode 100644 index 00000000..ca4b646c --- /dev/null +++ b/src/checks/level1/README-qhash-namespace.md @@ -0,0 +1,4 @@ +# qhash-namespace + +Warns when a `qHash()` function is not declared inside the namespace of it's argument. +`qHash()` needs to be inside the namespace for ADL lookup to happen. diff --git a/src/checks/level1/qhash-namespace.cpp b/src/checks/level1/qhash-namespace.cpp new file mode 100644 index 00000000..ad8562c2 --- /dev/null +++ b/src/checks/level1/qhash-namespace.cpp @@ -0,0 +1,68 @@ +/* + This file is part of the clazy static checker. + + Copyright (C) 2017 Sergio Martins <smartins@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "qhash-namespace.h" +#include "Utils.h" +#include "HierarchyUtils.h" +#include "QtUtils.h" +#include "TypeUtils.h" +#include "ContextUtils.h" +#include "StringUtils.h" +#include "checkmanager.h" + +#include <clang/AST/AST.h> + +using namespace clang; +using namespace std; + + +qhash_namespace::qhash_namespace(const std::string &name, ClazyContext *context) + : CheckBase(name, context) +{ +} + +void qhash_namespace::VisitDecl(clang::Decl *decl) +{ + auto func = dyn_cast<FunctionDecl>(decl); + if (!func || isa<CXXMethodDecl>(func) || func->getNumParams() == 0 || func->getNameAsString() != "qHash") + return; + + ParmVarDecl *firstArg = func->getParamDecl(0); + NamespaceDecl *argumentNS = ContextUtils::namespaceForType(firstArg->getType()); + NamespaceDecl *qHashNS = ContextUtils::namespaceForFunction(func); + + std::string msg; + if (qHashNS && argumentNS) { + const string argumentNSstr = argumentNS->getQualifiedNameAsString(); + const string qhashNSstr = qHashNS->getQualifiedNameAsString(); + if (argumentNSstr != qhashNSstr) + msg = "Move qHash(" + StringUtils::simpleTypeName(firstArg->getType(), lo()) + ") to " + argumentNSstr + " namespace for ADL lookup"; + } else if (qHashNS && !argumentNS) { + msg = "Move qHash(" + StringUtils::simpleTypeName(firstArg->getType(), lo()) + ") out of namespace " + qHashNS->getQualifiedNameAsString(); + } else if (!qHashNS && argumentNS) { + msg = "Move qHash(" + StringUtils::simpleTypeName(firstArg->getType(), lo()) + ") into " + argumentNS->getQualifiedNameAsString() + " namespace for ADL lookup"; + } + + if (!msg.empty()) + emitWarning(decl, msg); +} + +REGISTER_CHECK("qhash-namespace", qhash_namespace, CheckLevel1) diff --git a/src/checks/level1/qhash-namespace.h b/src/checks/level1/qhash-namespace.h new file mode 100644 index 00000000..820ca541 --- /dev/null +++ b/src/checks/level1/qhash-namespace.h @@ -0,0 +1,39 @@ +/* + This file is part of the clazy static checker. + + Copyright (C) 2017 Sergio Martins <smartins@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef CLAZY_QHASH_NAMESPACE_H +#define CLAZY_QHASH_NAMESPACE_H + +#include "checkbase.h" + + +/** + * See README-qhash-namespace.md for more info. + */ +class qhash_namespace : public CheckBase +{ +public: + explicit qhash_namespace(const std::string &name, ClazyContext *context); + void VisitDecl(clang::Decl *decl) override; +private: +}; + +#endif diff --git a/tests/clazy/test_requested_checks.sh.expected b/tests/clazy/test_requested_checks.sh.expected index e6e8e6fb..7c180189 100644 --- a/tests/clazy/test_requested_checks.sh.expected +++ b/tests/clazy/test_requested_checks.sh.expected @@ -1,6 +1,6 @@ -Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic Invalid check: foo -Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic Requested checks: foreach Requested checks: foreach, writing-to-temporary Invalid check: foo @@ -8,18 +8,18 @@ Requested checks: foreach, writing-to-temporary Requested checks: old-style-connect Requested checks: old-style-connect Requested checks: foreach, old-style-connect -Requested checks: auto-unexpected-qstringbuilder, base-class-event, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, container-inside-loop, copyable-polymorphic, ctor-missing-parent-argument, detaching-temporary, foreach, function-args-by-ref, function-args-by-value, global-const-char-pointer, implicit-casts, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, missing-qobject-macro, missing-typeinfo, mutable-container-key, non-pod-global-static, old-style-connect, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-allocations, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, reserve-candidates, returning-data-from-temporary, returning-void-expression, rule-of-three, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-call-ctor, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, base-class-event, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, container-inside-loop, copyable-polymorphic, ctor-missing-parent-argument, detaching-temporary, foreach, function-args-by-ref, function-args-by-value, global-const-char-pointer, implicit-casts, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, missing-qobject-macro, missing-typeinfo, mutable-container-key, non-pod-global-static, old-style-connect, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-allocations, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, reserve-candidates, returning-data-from-temporary, returning-void-expression, rule-of-three, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-call-ctor, virtual-signal, writing-to-temporary, wrong-qglobalstatic Requested checks: implicit-casts Requested checks: foreach, implicit-casts Requested checks: old-style-connect Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic -Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, reserve-candidates, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, foreach, implicit-casts, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic -Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic Test9 -Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, reserve-candidates, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, implicit-casts, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qenums, qfileinfo-exists, qgetenv, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, reserve-candidates, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic Requested checks: implicit-casts @@ -63,6 +63,7 @@ Available checks and FixIts: - overridden-signal - post-event - qdeleteall + - qhash-namespace - qlatin1string-non-ascii - qproperty-without-notify - qstring-left @@ -113,6 +114,6 @@ Backup your code before running them. Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qfileinfo-exists, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic Requested checks: implicit-casts Requested checks: implicit-casts -Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qenums, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic Requested checks: connect-non-signal, connect-not-normalized, container-anti-pattern, lambda-in-connect, mutable-container-key, qcolor-from-literal, qdatetime-utc, qfileinfo-exists, qmap-with-pointer-key, qstring-arg, qstring-insensitive-allocation, qstring-ref, qt-macros, qvariant-template-instantiation, strict-iterators, temporary-iterator, unused-non-trivial-variable, writing-to-temporary, wrong-qglobalstatic -Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qfileinfo-exists, qgetenv, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic +Requested checks: auto-unexpected-qstringbuilder, child-event-qobject-cast, connect-3arg-lambda, connect-non-signal, connect-not-normalized, container-anti-pattern, detaching-temporary, foreach, incorrect-emit, inefficient-qlist-soft, install-event-filter, lambda-in-connect, mutable-container-key, non-pod-global-static, overridden-signal, post-event, qcolor-from-literal, qdatetime-utc, qdeleteall, qfileinfo-exists, qgetenv, qhash-namespace, qlatin1string-non-ascii, qmap-with-pointer-key, qproperty-without-notify, qstring-arg, qstring-insensitive-allocation, qstring-left, qstring-ref, qt-macros, qvariant-template-instantiation, range-loop, returning-data-from-temporary, rule-of-two-soft, strict-iterators, temporary-iterator, unused-non-trivial-variable, virtual-signal, writing-to-temporary, wrong-qglobalstatic diff --git a/tests/qhash-namespace/config.json b/tests/qhash-namespace/config.json new file mode 100644 index 00000000..e7e6e0cb --- /dev/null +++ b/tests/qhash-namespace/config.json @@ -0,0 +1,7 @@ +{ + "tests" : [ + { + "filename" : "main.cpp" + } + ] +} diff --git a/tests/qhash-namespace/main.cpp b/tests/qhash-namespace/main.cpp new file mode 100644 index 00000000..7c7e3294 --- /dev/null +++ b/tests/qhash-namespace/main.cpp @@ -0,0 +1,22 @@ +#include <QtCore/QString> + +struct A { }; +uint qHash(A) { return 0; }; // OK + +namespace NS { + typedef int IntFoo; + struct B { struct B2 {}; struct B3 {}; }; + uint qHash(B) { return 0; }; // OK + uint qHash(B::B2) { return 0; }; // OK + namespace NS2 { + struct C {}; + uint qHash(C) { return 0; }; // OK + } + uint qHash(NS2::C) { return 0; }; // Warn + uint qHash(::A) { return 0; } // Warn + uint qHash(B::B3) { return 0; }; // OK +} +uint qHash(NS::B) { return 0; } // Warn +uint qHash(NS::B *) { return 0; } // Warn +uint qHash(NS::B::B3) { return 0; }; // Warn +uint qHash(NS::IntFoo) { return 0; } diff --git a/tests/qhash-namespace/main.cpp.expected b/tests/qhash-namespace/main.cpp.expected new file mode 100644 index 00000000..22658032 --- /dev/null +++ b/tests/qhash-namespace/main.cpp.expected @@ -0,0 +1,6 @@ +qhash-namespace/main.cpp:15:5: warning: Move qHash(NS::NS2::C) to NS::NS2 namespace for ADL lookup [-Wclazy-qhash-namespace] +qhash-namespace/main.cpp:16:5: warning: Move qHash(A) out of namespace NS [-Wclazy-qhash-namespace] +qhash-namespace/main.cpp:19:1: warning: Move qHash(NS::B) into NS namespace for ADL lookup [-Wclazy-qhash-namespace] +qhash-namespace/main.cpp:20:1: warning: Move qHash(NS::B *) into NS namespace for ADL lookup [-Wclazy-qhash-namespace] +qhash-namespace/main.cpp:21:1: warning: Move qHash(NS::B::B3) into NS namespace for ADL lookup [-Wclazy-qhash-namespace] +qhash-namespace/main.cpp:22:1: warning: Move qHash(NS::IntFoo) into NS namespace for ADL lookup [-Wclazy-qhash-namespace] |