Kaydet (Commit) 9308f353 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapt to Clang 3.4 (in preparation of a buildbot on CentOS 7)

Change-Id: Ie2859f03b31c57deb7fd0deba3285f782e33b239
üst 36936d5a
......@@ -323,6 +323,27 @@ inline auto getAsTagDecl(clang::Type const& t) -> clang::TagDecl *
#endif
}
inline bool isStdNamespace(clang::DeclContext const & context) {
#if CLANG_VERSION >= 30500
return context.isStdNamespace();
#else
// cf. lib/AST/DeclBase.cpp:
if (!context.isNamespace()) {
return false;
}
const clang::NamespaceDecl *ND = clang::cast<clang::NamespaceDecl>(
&context);
if (ND->isInline()) {
return isStdNamespace(*ND->getParent());
}
if (!context.getParent()->getRedeclContext()->isTranslationUnit()) {
return false;
}
const clang::IdentifierInfo *II = ND->getIdentifier();
return II && II->isStr("std");
#endif
}
}
#endif
......
......@@ -9,6 +9,7 @@
#include <algorithm>
#include "clang/AST/Attr.h"
#include "clang/AST/CXXInheritance.h"
#include "plugin.hxx"
......
......@@ -21,7 +21,9 @@
#if CLANG_VERSION < 30700
template<> struct std::iterator_traits<ExprIterator> {
namespace std {
template<> struct iterator_traits<ExprIterator> {
typedef std::ptrdiff_t difference_type;
typedef Expr * value_type;
typedef Expr const ** pointer;
......@@ -29,7 +31,7 @@ template<> struct std::iterator_traits<ExprIterator> {
typedef std::random_access_iterator_tag iterator_category;
};
template<> struct std::iterator_traits<ConstExprIterator> {
template<> struct iterator_traits<ConstExprIterator> {
typedef std::ptrdiff_t difference_type;
typedef Expr const * value_type;
typedef Expr const ** pointer;
......@@ -37,6 +39,8 @@ template<> struct std::iterator_traits<ConstExprIterator> {
typedef std::random_access_iterator_tag iterator_category;
};
}
#endif
namespace {
......
......@@ -231,7 +231,7 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C
return;
}
const QualType type = functionDecl->getReturnType().getDesugaredType(compiler.getASTContext());
const QualType type = compat::getReturnType(*functionDecl).getDesugaredType(compiler.getASTContext());
if (type->isReferenceType() || type->isIntegralOrEnumerationType() || type->isPointerType()
|| type->isTemplateTypeParmType() || type->isDependentType() || type->isBuiltinType()
|| type->isScalarType())
......
......@@ -34,14 +34,14 @@ bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
{
return true;
}
for (auto const & i: decl->bases()) {
if (i.getAccessSpecifierAsWritten() == AS_none) {
for (auto i = decl->bases_begin(); i != decl->bases_end(); ++i) {
if (i->getAccessSpecifierAsWritten() == AS_none) {
report(
DiagnosticsEngine::Warning,
"base class is private by default; explicitly give an access"
" specifier",
i.getLocStart())
<< i.getSourceRange();
i->getLocStart())
<< i->getSourceRange();
}
}
return true;
......
......@@ -427,7 +427,7 @@ bool RefCounting::VisitFunctionDecl(const FunctionDecl * functionDecl) {
if (methodDecl && methodDecl->size_overridden_methods() > 0) {
return true;
}
checkUnoReference(functionDecl->getReturnType(), functionDecl, "", "return");
checkUnoReference(compat::getReturnType(*functionDecl), functionDecl, "", "return");
return true;
}
......
......@@ -258,7 +258,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
if (parent && isa<ReturnStmt>(parent)) {
const Stmt* parent2 = parentStmt(parent);
if (parent2 && isa<CompoundStmt>(parent2)) {
QualType qt = parentFunction->getReturnType().getDesugaredType(compiler.getASTContext());
QualType qt = compat::getReturnType(*parentFunction).getDesugaredType(compiler.getASTContext());
if (!qt.isConstQualified() && qt->isReferenceType()) {
assignValue = "?";
bPotentiallyAssignedTo = true;
......@@ -443,10 +443,10 @@ void SingleValFields::checkCallExpr(const Stmt* child, const CallExpr* callExpr,
return;
}
for (unsigned i = 0; i < callExpr->getNumArgs(); ++i) {
if (i >= proto->getNumParams()) // can happen in template code
if (i >= compat::getNumParams(*proto)) // can happen in template code
break;
if (callExpr->getArg(i) == child) {
QualType qt = proto->getParamTypes()[i].getDesugaredType(compiler.getASTContext());
QualType qt = compat::getParamType(*proto, i).getDesugaredType(compiler.getASTContext());
if (!qt.isConstQualified() && qt->isReferenceType()) {
assignValue = "?";
bPotentiallyAssignedTo = true;
......
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "clang/AST/Attr.h"
#include "plugin.hxx"
#include "compat.hxx"
......
......@@ -81,7 +81,8 @@ TerminalCheck NamespaceCheck::GlobalNamespace() const {
}
TerminalCheck NamespaceCheck::StdNamespace() const {
return TerminalCheck(context_ != nullptr && context_->isStdNamespace());
return TerminalCheck(
context_ != nullptr && compat::isStdNamespace(*context_));
}
}
......
......@@ -12,6 +12,8 @@
#include <iostream>
#include <fstream>
#include "clang/AST/Attr.h"
#include "plugin.hxx"
#include "compat.hxx"
......
......@@ -12,6 +12,9 @@
#include <iostream>
#include <fstream>
#include <set>
#include "clang/AST/Attr.h"
#include "plugin.hxx"
#include "compat.hxx"
......@@ -265,7 +268,7 @@ gotfunc:
}
// Now do the checks necessary for the "unused return value" analysis
if (calleeFunctionDecl->getReturnType()->isVoidType()) {
if (compat::getReturnType(*calleeFunctionDecl)->isVoidType()) {
return true;
}
if (!parent) {
......
......@@ -205,9 +205,11 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD
if (pCompoundStatement) {
bool bFoundDisposeOnce = false;
int nNumExtraStatements = 0;
for(auto const * x : pCompoundStatement->body())
for (auto i = pCompoundStatement->body_begin();
i != pCompoundStatement->body_end(); ++i)
{
const CXXMemberCallExpr *pCallExpr = dyn_cast<CXXMemberCallExpr>(x);
const CXXMemberCallExpr *pCallExpr = dyn_cast<CXXMemberCallExpr>(
*i);
if (pCallExpr) {
if( const FunctionDecl* func = pCallExpr->getDirectCallee()) {
if( func->getNumParams() == 0 && func->getIdentifier() != NULL
......@@ -217,7 +219,7 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD
}
}
// checking for ParenExpr is a hacky way to ignore assert statements in older versions of clang (i.e. <= 3.2)
if (!pCallExpr && !dyn_cast<ParenExpr>(x))
if (!pCallExpr && !dyn_cast<ParenExpr>(*i))
nNumExtraStatements++;
}
bOk = bFoundDisposeOnce && nNumExtraStatements == 0;
......
......@@ -98,10 +98,11 @@ public:
}
CompoundStmt const*const pCompoundStatement(
dyn_cast<CompoundStmt>(pMethodDecl->getBody()));
for (auto const pStmt : pCompoundStatement->body())
for (auto i = pCompoundStatement->body_begin();
i != pCompoundStatement->body_end(); ++i)
{
// note: this is not a CXXMemberCallExpr
CallExpr const*const pCallExpr(dyn_cast<CallExpr>(pStmt));
CallExpr const*const pCallExpr(dyn_cast<CallExpr>(*i));
if (pCallExpr)
{
// note: this is only sometimes a CXXMethodDecl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment