/* SPDX-FileCopyrightText: 2016 Sergio Martins SPDX-License-Identifier: LGPL-2.0-or-later */ #include "returning-void-expression.h" #include "ClazyContext.h" #include "ContextUtils.h" #include "clazy_stl.h" #include #include #include #include #include #include using namespace clang; void ReturningVoidExpression::VisitStmt(clang::Stmt *stmt) { auto *ret = dyn_cast(stmt); if (!ret || !clazy::hasChildren(ret)) { return; } QualType qt = ret->getRetValue()->getType(); if (qt.isNull() || !qt->isVoidType()) { return; } DeclContext *context = clazy::contextForDecl(m_context->lastDecl); if (!context) { return; } auto *func = dyn_cast(context); // A function template returning T won't bailout in the void check above, do it properly now: if (!func || !func->getReturnType()->isVoidType()) { return; } emitWarning(stmt, "Returning a void expression"); }