void QHashNamespace::VisitDecl()

in src/checks/level1/qhash-namespace.cpp [29:64]


void QHashNamespace::VisitDecl(clang::Decl *decl)
{
    auto *func = dyn_cast<FunctionDecl>(decl);
    if (!func || isa<CXXMethodDecl>(func) || func->getNumParams() == 0 || clazy::name(func) != "qHash") {
        return;
    }

    ParmVarDecl *firstArg = func->getParamDecl(0);
    NamespaceDecl *argumentNS = clazy::namespaceForType(firstArg->getType());
    NamespaceDecl *qHashNS = clazy::namespaceForFunction(func);

    std::string msg;
    if (qHashNS && argumentNS) {
        const std::string argumentNSstr = argumentNS->getQualifiedNameAsString();
        const std::string qhashNSstr = qHashNS->getQualifiedNameAsString();
        if (argumentNSstr != qhashNSstr) {
            msg = "Move qHash(" + clazy::simpleTypeName(firstArg->getType(), lo()) + ") to " + argumentNSstr + " namespace for ADL lookup";
        }
    } else if (qHashNS && !argumentNS) {
        msg = "Move qHash(" + clazy::simpleTypeName(firstArg->getType(), lo()) + ") out of namespace " + qHashNS->getQualifiedNameAsString();
    } else if (!qHashNS && argumentNS) {
        msg =
            "Move qHash(" + clazy::simpleTypeName(firstArg->getType(), lo()) + ") into " + argumentNS->getQualifiedNameAsString() + " namespace for ADL lookup";
    }

    if (!msg.empty()) {
        emitWarning(decl, msg);
    }

    if (m_context->isQtDeveloper()) {
        PreProcessorVisitor *preProcessorVisitor = m_context->preprocessorVisitor;
        if (preProcessorVisitor && !preProcessorVisitor->isBetweenQtNamespaceMacros(func->getBeginLoc())) {
            emitWarning(decl, "qHash(" + clazy::simpleTypeName(firstArg->getType(), lo()) + ") must be declared before QT_END_NAMESPACE");
        }
    }
}