Kaydet (Commit) 3cc5149a authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Avoid -Werror=deprecated-declarations with recent Clang trunk

...which first added alternative names to and then deprecated getLocBegin/End

Change-Id: Iaefb8ce259057abfa6cd20f0b63c0ef2949a96b2
Reviewed-on: https://gerrit.libreoffice.org/58820
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst d1a19ef6
......@@ -51,7 +51,7 @@ bool AutoMem::VisitCXXDeleteExpr(const CXXDeleteExpr* expr)
{
if (ignoreLocation( expr ))
return true;
StringRef aFileName = getFileNameOfSpellingLoc(compiler.getSourceManager().getSpellingLoc(expr->getLocStart()));
StringRef aFileName = getFileNameOfSpellingLoc(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr)));
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/salhelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/osl/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/salhelper/")
......@@ -79,7 +79,7 @@ bool AutoMem::VisitCXXDeleteExpr(const CXXDeleteExpr* expr)
report(
DiagnosticsEngine::Warning,
"calling delete on object field, rather use std::unique_ptr or std::scoped_ptr",
expr->getLocStart())
compat::getBeginLoc(expr))
<< expr->getSourceRange();
return true;
}
......
......@@ -47,9 +47,9 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound)
auto inner = *compound->body_begin();
if (!isa<CompoundStmt>(inner))
return true;
if (compiler.getSourceManager().isMacroBodyExpansion(compound->getLocStart()))
if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(compound)))
return true;
if (compiler.getSourceManager().isMacroBodyExpansion(inner->getLocStart()))
if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(inner)))
return true;
if (containsPreprocessingConditionalInclusion(compound->getSourceRange())) {
return true;
......@@ -57,12 +57,12 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound)
report(
DiagnosticsEngine::Warning,
"block directly inside block",
compound->getLocStart())
compat::getBeginLoc(compound))
<< compound->getSourceRange();
report(
DiagnosticsEngine::Note,
"inner block here",
inner->getLocStart())
compat::getBeginLoc(inner))
<< inner->getSourceRange();
return true;
}
......
......@@ -440,7 +440,7 @@ private:
return nullptr;
}
if (compiler.getSourceManager().isMacroBodyExpansion(
expr->getLocStart()))
compat::getBeginLoc(expr)))
{
return nullptr;
}
......@@ -487,7 +487,7 @@ private:
if (usage.firstConsumption != nullptr) {
return;
}
auto const loc = dre->getLocStart();
auto const loc = compat::getBeginLoc(dre);
if (compiler.getSourceManager().isMacroArgExpansion(loc)
&& (compat::getImmediateMacroNameForDiagnostics(
loc, compiler.getSourceManager(), compiler.getLangOpts())
......
......@@ -111,7 +111,7 @@ bool ChangeToolsGen::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call)
if (auto unaryOp = dyn_cast<UnaryOperator>(parent))
{
if (!ChangeUnaryOperator(unaryOp, call, methodName))
report(DiagnosticsEngine::Warning, "Could not fix, unary", call->getLocStart());
report(DiagnosticsEngine::Warning, "Could not fix, unary", compat::getBeginLoc(call));
return true;
}
auto binaryOp = dyn_cast<BinaryOperator>(parent);
......@@ -130,7 +130,7 @@ bool ChangeToolsGen::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call)
if (parent2 && isa<Expr>(parent2))
{
report(DiagnosticsEngine::Warning, "Could not fix, embedded assign",
call->getLocStart());
compat::getBeginLoc(call));
return true;
}
// Check for
......@@ -139,25 +139,25 @@ bool ChangeToolsGen::VisitCXXMemberCallExpr(CXXMemberCallExpr const* call)
if (rhs->getOpcode() == BO_Assign)
{
report(DiagnosticsEngine::Warning, "Could not fix, double assign",
call->getLocStart());
compat::getBeginLoc(call));
return true;
}
if (!ChangeAssignment(parent, methodName, setPrefix))
report(DiagnosticsEngine::Warning, "Could not fix, assign", call->getLocStart());
report(DiagnosticsEngine::Warning, "Could not fix, assign", compat::getBeginLoc(call));
return true;
}
if (opcode == BO_AddAssign || opcode == BO_SubAssign)
{
if (!ChangeBinaryOperatorPlusMinus(binaryOp, call, methodName))
report(DiagnosticsEngine::Warning, "Could not fix, assign-and-change",
call->getLocStart());
compat::getBeginLoc(call));
return true;
}
else if (opcode == BO_RemAssign || opcode == BO_MulAssign || opcode == BO_DivAssign)
{
if (!ChangeBinaryOperatorOther(binaryOp, call, methodName, setPrefix))
report(DiagnosticsEngine::Warning, "Could not fix, assign-and-change",
call->getLocStart());
compat::getBeginLoc(call));
return true;
}
else
......@@ -173,8 +173,8 @@ bool ChangeToolsGen::ChangeAssignment(Stmt const* parent, std::string const& met
// and replace with
// aRect.SetLeft( ... );
SourceManager& SM = compiler.getSourceManager();
SourceLocation startLoc = SM.getExpansionLoc(parent->getLocStart());
SourceLocation endLoc = SM.getExpansionLoc(parent->getLocEnd());
SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(parent));
SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(parent));
const char* p1 = SM.getCharacterData(startLoc);
const char* p2 = SM.getCharacterData(endLoc);
unsigned n = Lexer::MeasureTokenLength(endLoc, SM, compiler.getLangOpts());
......@@ -201,8 +201,8 @@ bool ChangeToolsGen::ChangeBinaryOperatorPlusMinus(BinaryOperator const* binaryO
// and replace with
// aRect.MoveLeft( ... );
SourceManager& SM = compiler.getSourceManager();
SourceLocation startLoc = SM.getExpansionLoc(binaryOp->getLocStart());
SourceLocation endLoc = SM.getExpansionLoc(binaryOp->getLocEnd());
SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(binaryOp));
SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(binaryOp));
const char* p1 = SM.getCharacterData(startLoc);
const char* p2 = SM.getCharacterData(endLoc);
if (p2 < p1) // clang is misbehaving, appears to be macro constant related
......@@ -228,7 +228,7 @@ bool ChangeToolsGen::ChangeBinaryOperatorPlusMinus(BinaryOperator const* binaryO
if (newText == callText)
{
report(DiagnosticsEngine::Warning, "binaryop-plusminus regex match failed",
call->getLocStart());
compat::getBeginLoc(call));
return false;
}
......@@ -245,8 +245,8 @@ bool ChangeToolsGen::ChangeBinaryOperatorOther(BinaryOperator const* binaryOp,
// and replace with
// aRect.SetLeft( aRect.GetLeft() + ... );
SourceManager& SM = compiler.getSourceManager();
SourceLocation startLoc = SM.getExpansionLoc(binaryOp->getLocStart());
SourceLocation endLoc = SM.getExpansionLoc(binaryOp->getLocEnd());
SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(binaryOp));
SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(binaryOp));
const char* p1 = SM.getCharacterData(startLoc);
const char* p2 = SM.getCharacterData(endLoc);
if (p2 < p1) // clang is misbehaving, appears to be macro constant related
......@@ -284,7 +284,7 @@ bool ChangeToolsGen::ChangeBinaryOperatorOther(BinaryOperator const* binaryOp,
if (newText == callText)
{
report(DiagnosticsEngine::Warning, "binaryop-other regex match failed %0",
call->getLocStart())
compat::getBeginLoc(call))
<< reString;
return false;
}
......@@ -308,8 +308,8 @@ bool ChangeToolsGen::ChangeUnaryOperator(UnaryOperator const* unaryOp,
// aRect.MoveLeft( 1 );
SourceManager& SM = compiler.getSourceManager();
SourceLocation startLoc = SM.getExpansionLoc(unaryOp->getLocStart());
SourceLocation endLoc = SM.getExpansionLoc(unaryOp->getLocEnd());
SourceLocation startLoc = SM.getExpansionLoc(compat::getBeginLoc(unaryOp));
SourceLocation endLoc = SM.getExpansionLoc(compat::getEndLoc(unaryOp));
const char* p1 = SM.getCharacterData(startLoc);
const char* p2 = SM.getCharacterData(endLoc);
if (p2 < p1) // clang is misbehaving, appears to be macro constant related
......@@ -352,7 +352,8 @@ bool ChangeToolsGen::ChangeUnaryOperator(UnaryOperator const* unaryOp,
}
if (newText == callText)
{
report(DiagnosticsEngine::Warning, "unaryop regex match failed %0", call->getLocStart())
report(DiagnosticsEngine::Warning, "unaryop regex match failed %0",
compat::getBeginLoc(call))
<< reString;
return false;
}
......
......@@ -199,7 +199,7 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) {
return true;
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(canon->getLocation())))
return true;
StringRef fn = getFileNameOfSpellingLoc(compiler.getSourceManager().getSpellingLoc(canon->getLocStart()));
StringRef fn = getFileNameOfSpellingLoc(compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(canon)));
// Some backwards compat magic.
// TODO Can probably be removed, but need to do some checking
if (loplugin::isSamePathname(fn, SRCDIR "/include/sax/fshelper.hxx"))
......@@ -471,7 +471,7 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) {
continue;
}
report( DiagnosticsEngine::Warning,
"unused param %0 in %1", param->getLocStart())
"unused param %0 in %1", compat::getBeginLoc(param))
<< param->getSourceRange()
<< param->getName()
<< fqn;
......@@ -480,7 +480,7 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) {
unsigned idx = param->getFunctionScopeIndex();
const ParmVarDecl* pOther = canon->getParamDecl(idx);
report( DiagnosticsEngine::Note, "declaration is here",
pOther->getLocStart())
compat::getBeginLoc(pOther))
<< pOther->getSourceRange();
}
}
......
......@@ -97,11 +97,11 @@ bool CommaOperator::VisitBinComma(const BinaryOperator* binaryOp)
// winsock2.h (TODO: improve heuristic of determining that the whole
// binaryOp is part of a single macro body expansion):
if (compiler.getSourceManager().isMacroBodyExpansion(
binaryOp->getLocStart())
compat::getBeginLoc(binaryOp))
&& compiler.getSourceManager().isMacroBodyExpansion(
binaryOp->getOperatorLoc())
&& compiler.getSourceManager().isMacroBodyExpansion(
binaryOp->getLocEnd())
compat::getEndLoc(binaryOp))
&& ignoreLocation(
compiler.getSourceManager().getSpellingLoc(
binaryOp->getOperatorLoc())))
......
......@@ -14,6 +14,7 @@
#include <utility>
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/Basic/SourceManager.h"
......@@ -50,6 +51,70 @@ inline clang::FunctionDecl::param_const_range parameters(
}
#endif
inline clang::SourceLocation getBeginLoc(clang::Decl const * decl) {
#if CLANG_VERSION >= 80000
return decl->getBeginLoc();
#else
return decl->getLocStart();
#endif
}
inline clang::SourceLocation getEndLoc(clang::Decl const * decl) {
#if CLANG_VERSION >= 80000
return decl->getEndLoc();
#else
return decl->getLocEnd();
#endif
}
inline clang::SourceLocation getBeginLoc(clang::DeclarationNameInfo const & info) {
#if CLANG_VERSION >= 80000
return info.getBeginLoc();
#else
return info.getLocStart();
#endif
}
inline clang::SourceLocation getEndLoc(clang::DeclarationNameInfo const & info) {
#if CLANG_VERSION >= 80000
return info.getEndLoc();
#else
return info.getLocEnd();
#endif
}
inline clang::SourceLocation getBeginLoc(clang::Stmt const * stmt) {
#if CLANG_VERSION >= 80000
return stmt->getBeginLoc();
#else
return stmt->getLocStart();
#endif
}
inline clang::SourceLocation getEndLoc(clang::Stmt const * stmt) {
#if CLANG_VERSION >= 80000
return stmt->getEndLoc();
#else
return stmt->getLocEnd();
#endif
}
inline clang::SourceLocation getBeginLoc(clang::CXXBaseSpecifier const * spec) {
#if CLANG_VERSION >= 80000
return spec->getBeginLoc();
#else
return spec->getLocStart();
#endif
}
inline clang::SourceLocation getEndLoc(clang::CXXBaseSpecifier const * spec) {
#if CLANG_VERSION >= 80000
return spec->getEndLoc();
#else
return spec->getLocEnd();
#endif
}
inline std::pair<clang::SourceLocation, clang::SourceLocation> getImmediateExpansionRange(
clang::SourceManager const & SM, clang::SourceLocation Loc)
{
......
......@@ -199,8 +199,8 @@ std::string ConstantParam::getCallValue(const Expr* arg)
// Get the expression contents.
// This helps us find params which are always initialised with something like "OUString()".
SourceManager& SM = compiler.getSourceManager();
SourceLocation startLoc = arg->getLocStart();
SourceLocation endLoc = arg->getLocEnd();
SourceLocation startLoc = compat::getBeginLoc(arg);
SourceLocation endLoc = compat::getEndLoc(arg);
const char *p1 = SM.getCharacterData( startLoc );
const char *p2 = SM.getCharacterData( endLoc );
if (!p1 || !p2 || (p2 - p1) < 0 || (p2 - p1) > 40) {
......
......@@ -79,7 +79,7 @@ public:
report(
DiagnosticsEngine::Warning,
"this parameter can be const",
pParmVarDecl->getLocStart())
compat::getBeginLoc(pParmVarDecl))
<< pParmVarDecl->getSourceRange();
if (canonicalDecl->getLocation() != functionDecl->getLocation()) {
unsigned idx = pParmVarDecl->getFunctionScopeIndex();
......@@ -87,7 +87,7 @@ public:
report(
DiagnosticsEngine::Note,
"canonical parameter declaration here",
pOther->getLocStart())
compat::getBeginLoc(pOther))
<< pOther->getSourceRange();
}
//functionDecl->dump();
......@@ -172,13 +172,13 @@ bool ConstParams::CheckTraverseFunctionDecl(FunctionDecl * functionDecl)
// ignore the macros from include/tools/link.hxx
auto canonicalDecl = functionDecl->getCanonicalDecl();
if (compiler.getSourceManager().isMacroBodyExpansion(canonicalDecl->getLocStart())
|| compiler.getSourceManager().isMacroArgExpansion(canonicalDecl->getLocStart())) {
if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(canonicalDecl))
|| compiler.getSourceManager().isMacroArgExpansion(compat::getBeginLoc(canonicalDecl))) {
StringRef name { Lexer::getImmediateMacroName(
canonicalDecl->getLocStart(), compiler.getSourceManager(), compiler.getLangOpts()) };
compat::getBeginLoc(canonicalDecl), compiler.getSourceManager(), compiler.getLangOpts()) };
if (name.startswith("DECL_LINK") || name.startswith("DECL_STATIC_LINK"))
return false;
auto loc2 = compat::getImmediateExpansionRange(compiler.getSourceManager(), canonicalDecl->getLocStart()).first;
auto loc2 = compat::getImmediateExpansionRange(compiler.getSourceManager(), compat::getBeginLoc(canonicalDecl)).first;
if (compiler.getSourceManager().isMacroBodyExpansion(loc2))
{
StringRef name2 { Lexer::getImmediateMacroName(
......@@ -300,7 +300,7 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar
report(
DiagnosticsEngine::Warning,
"no parent?",
stmt->getLocStart())
compat::getBeginLoc(stmt))
<< stmt->getSourceRange();
return false;
}
......@@ -549,7 +549,7 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar
report(
DiagnosticsEngine::Warning,
"oh dear, what can the matter be?",
parent->getLocStart())
compat::getBeginLoc(parent))
<< parent->getSourceRange();
return true;
}
......
......@@ -170,7 +170,7 @@ bool CountUsersOfDefaultParams::VisitCallExpr(const CallExpr * callExpr) {
if ( n < (int)callExpr->getNumArgs() && callExpr->getArg(n)->isDefaultArgument()) {
MyCallInfo callInfo;
niceName(functionDecl, callInfo);
callInfo.sourceLocationOfCall = locationToString(callExpr->getLocStart());
callInfo.sourceLocationOfCall = locationToString(compat::getBeginLoc(callExpr));
callSet.insert(callInfo);
}
return true;
......@@ -199,7 +199,7 @@ bool CountUsersOfDefaultParams::VisitCXXConstructExpr(const CXXConstructExpr * c
if ( n < (int)constructExpr->getNumArgs() && constructExpr->getArg(n)->isDefaultArgument()) {
MyCallInfo callInfo;
niceName(constructorDecl, callInfo);
callInfo.sourceLocationOfCall = locationToString(constructExpr->getLocStart());
callInfo.sourceLocationOfCall = locationToString(compat::getBeginLoc(constructExpr));
callSet.insert(callInfo);
}
return true;
......
......@@ -234,7 +234,7 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) {
if( expr->getCastKind() == CK_ToVoid ) {
return true;
}
if (isSharedCAndCppCode(expr->getLocStart())) {
if (isSharedCAndCppCode(compat::getBeginLoc(expr))) {
return true;
}
char const * perf = nullptr;
......@@ -407,8 +407,8 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const *
firstBegin = compiler.getSourceManager().getSpellingLoc(firstBegin);
secondBegin = compiler.getSourceManager().getSpellingLoc(secondBegin);
}
auto third = sub->getLocStart();
auto fourth = sub->getLocEnd();
auto third = compat::getBeginLoc(sub);
auto fourth = compat::getEndLoc(sub);
bool macro = false;
// Ensure that
//
......
......@@ -45,7 +45,7 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl)
return true;
}
StringRef aFileName = getFileNameOfSpellingLoc(
compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart()));
compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(fieldDecl)));
// FIXME complex stuff to fix later
......@@ -97,13 +97,13 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl)
sPath += baseCXXRecordDecl->getNameAsString();
report(DiagnosticsEngine::Warning,
"data member %0 is shadowing member in superclass, through inheritance path %1",
fieldDecl->getLocStart())
compat::getBeginLoc(fieldDecl))
<< fieldDecl->getName()
<< sPath
<< fieldDecl->getSourceRange();
report(DiagnosticsEngine::Note,
"superclass member here",
baseFieldDecl->getLocStart())
compat::getBeginLoc(baseFieldDecl))
<< baseFieldDecl->getSourceRange();
}
return false;
......
......@@ -69,7 +69,7 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call)
if (!currCatchStmt)
{
report(DiagnosticsEngine::Warning, "DBG_UNHANDLED_EXCEPTION outside catch block",
call->getLocStart());
compat::getBeginLoc(call));
return true;
}
auto catchBlock = dyn_cast<CompoundStmt>(currCatchStmt->getHandlerBlock());
......@@ -77,14 +77,14 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call)
{
report(DiagnosticsEngine::Warning,
"something wrong with DBG_UNHANDLED_EXCEPTION, no CompoundStmt?",
call->getLocStart());
compat::getBeginLoc(call));
return true;
}
if (catchBlock->size() < 1)
{
report(DiagnosticsEngine::Warning,
"something wrong with DBG_UNHANDLED_EXCEPTION, CompoundStmt size == 0?",
call->getLocStart());
compat::getBeginLoc(call));
return true;
}
......@@ -95,7 +95,7 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call)
{
report(DiagnosticsEngine::Warning,
"DBG_UNHANDLED_EXCEPTION must be first statement in catch block",
call->getLocStart());
compat::getBeginLoc(call));
}
return true;
}
......
......@@ -32,7 +32,7 @@ bool DerefNullPtr::VisitUnaryDeref(UnaryOperator const * op) {
{
report(
DiagnosticsEngine::Warning, "null pointer dereference",
op->getLocStart())
compat::getBeginLoc(op))
<< op->getSourceRange();
}
return true;
......
......@@ -41,7 +41,7 @@ bool DodgySwitch::VisitDefaultStmt(DefaultStmt const * defaultStmt)
if (!IsParentSwitch(defaultStmt))
report(
DiagnosticsEngine::Warning, "default statement not directly under switch",
defaultStmt->getLocStart())
compat::getBeginLoc(defaultStmt))
<< defaultStmt->getSourceRange();
return true;
}
......@@ -55,7 +55,7 @@ bool DodgySwitch::VisitCaseStmt(CaseStmt const * caseStmt)
//parentStmt(parentStmt(caseStmt))->dump();
report(
DiagnosticsEngine::Warning, "case statement not directly under switch",
caseStmt->getLocStart())
compat::getBeginLoc(caseStmt))
<< caseStmt->getSourceRange();
}
return true;
......
......@@ -69,14 +69,15 @@ bool EmptyIf::VisitIfStmt(IfStmt const* ifStmt)
if (ifStmt->getElse() && empty(ifStmt->getElse()) && !ContainsComment(ifStmt->getElse()))
{
report(DiagnosticsEngine::Warning, "empty else body", ifStmt->getElse()->getLocStart())
report(DiagnosticsEngine::Warning, "empty else body",
compat::getBeginLoc(ifStmt->getElse()))
<< ifStmt->getElse()->getSourceRange();
return true;
}
if (!ifStmt->getElse() && empty(ifStmt->getThen()) && !ContainsComment(ifStmt->getThen()))
{
report(DiagnosticsEngine::Warning, "empty if body", ifStmt->getLocStart())
report(DiagnosticsEngine::Warning, "empty if body", compat::getBeginLoc(ifStmt))
<< ifStmt->getSourceRange();
}
......
......@@ -268,7 +268,7 @@ void ExpandableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct
return;
}
calledFromSet.emplace(toString(expr->getLocStart()), niceName(canonicalFunctionDecl));
calledFromSet.emplace(toString(compat::getBeginLoc(expr)), niceName(canonicalFunctionDecl));
if (const UnaryOperator* unaryOp = dyn_cast_or_null<UnaryOperator>(getParentStmt(expr))) {
if (unaryOp->getOpcode() == UO_AddrOf) {
......
......@@ -73,7 +73,7 @@ bool ExpressionAlwaysZero::VisitBinaryOperator( BinaryOperator const * binaryOpe
{
if (ignoreLocation(binaryOperator))
return true;
if (binaryOperator->getLocStart().isMacroID())
if (compat::getBeginLoc(binaryOperator).isMacroID())
return true;
auto op = binaryOperator->getOpcode();
......@@ -92,7 +92,7 @@ bool ExpressionAlwaysZero::VisitBinaryOperator( BinaryOperator const * binaryOpe
return true;
report(
DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1",
binaryOperator->getLocStart())
compat::getBeginLoc(binaryOperator))
<< (lhsValue ? lhsValue->toString(10) : "unknown")
<< (rhsValue ? rhsValue->toString(10) : "unknown")
<< binaryOperator->getSourceRange();
......@@ -103,7 +103,7 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const *
{
if (ignoreLocation(cxxOperatorCallExpr))
return true;
if (cxxOperatorCallExpr->getLocStart().isMacroID())
if (compat::getBeginLoc(cxxOperatorCallExpr).isMacroID())
return true;
auto op = cxxOperatorCallExpr->getOperator();
......@@ -124,7 +124,7 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const *
return true;
report(
DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1",
cxxOperatorCallExpr->getLocStart())
compat::getBeginLoc(cxxOperatorCallExpr))
<< (lhsValue ? lhsValue->toString(10) : "unknown")
<< (rhsValue ? rhsValue->toString(10) : "unknown")
<< cxxOperatorCallExpr->getSourceRange();
......
......@@ -116,7 +116,7 @@ bool FailedDynCast::VisitCXXDynamicCastExpr(CXXDynamicCastExpr const * expr) {
if (isAlwaysNull(expr)) {
report(
DiagnosticsEngine::Warning,
"dynamic_cast from %0 to %1 always fails", expr->getLocStart())
"dynamic_cast from %0 to %1 always fails", compat::getBeginLoc(expr))
<< expr->getSubExpr()->getType() << expr->getType()
<< expr->getSourceRange();
}
......
......@@ -127,7 +127,7 @@ bool FinalClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl)
if (ignoreClass(s))
return true;
SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(decl->getLocStart());
SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl));
std::string filename = compiler.getSourceManager().getFilename(spellingLocation);
auto sourceLocation = filename.substr(strlen(SRCDIR)) + ":"
+ std::to_string(compiler.getSourceManager().getSpellingLineNumber(spellingLocation));
......
......@@ -50,7 +50,7 @@ bool FinalProtected::VisitCXXMethodDecl(CXXMethodDecl const * cxxMethodDecl)
cxxMethodDecl = cxxMethodDecl->getCanonicalDecl();
report(DiagnosticsEngine::Warning,
"final class should not have protected members - convert them to private",
cxxMethodDecl->getLocStart())
compat::getBeginLoc(cxxMethodDecl))
<< cxxMethodDecl->getSourceRange();
return true;
}
......@@ -69,7 +69,7 @@ bool FinalProtected::VisitFieldDecl(FieldDecl const * fieldDecl)
fieldDecl = fieldDecl->getCanonicalDecl();
report(DiagnosticsEngine::Warning,
"final class should not have protected members - convert them to private",
fieldDecl->getLocStart())
compat::getBeginLoc(fieldDecl))
<< fieldDecl->getSourceRange();
return true;
}
......
......@@ -204,7 +204,7 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt)
report(
DiagnosticsEngine::Warning,
"large if statement at end of function, rather invert the condition and exit early, and flatten the function",
ifStmt->getLocStart())
compat::getBeginLoc(ifStmt))
<< ifStmt->getSourceRange();
}
return true;
......@@ -238,12 +238,12 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt)
report(
DiagnosticsEngine::Warning,
"unconditional throw in else branch, rather invert the condition, throw early, and flatten the normal case",
elseThrowExpr->getLocStart())
compat::getBeginLoc(elseThrowExpr))
<< elseThrowExpr->getSourceRange();
report(
DiagnosticsEngine::Note,
"if condition here",
ifStmt->getLocStart())
compat::getBeginLoc(ifStmt))
<< ifStmt->getSourceRange();
}
}
......@@ -260,7 +260,7 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt)
report(
DiagnosticsEngine::Warning,
"unconditional throw in then branch, just flatten the else",
thenThrowExpr->getLocStart())
compat::getBeginLoc(thenThrowExpr))
<< thenThrowExpr->getSourceRange();
}
}
......
......@@ -48,7 +48,7 @@ bool FragileDestructor::TraverseCXXDestructorDecl(CXXDestructorDecl* pCXXDestruc
}
// ignore this for now, too tricky for me to work out
StringRef aFileName = getFileNameOfSpellingLoc(
compiler.getSourceManager().getSpellingLoc(pCXXDestructorDecl->getLocStart()));
compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(pCXXDestructorDecl)));
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/comphelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/cppuhelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/cppuhelper/")
......@@ -80,15 +80,15 @@ bool FragileDestructor::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr
return true;
}
// if we see an explicit call to its own method, that's OK
auto s1 = compiler.getSourceManager().getCharacterData(callExpr->getLocStart());
auto s2 = compiler.getSourceManager().getCharacterData(callExpr->getLocEnd());
auto s1 = compiler.getSourceManager().getCharacterData(compat::getBeginLoc(callExpr));
auto s2 = compiler.getSourceManager().getCharacterData(compat::getEndLoc(callExpr));
std::string tok(s1, s2-s1);
if (tok.find("::") != std::string::npos) {
return true;
}
// e.g. osl/thread.hxx and cppuhelper/compbase.hxx
StringRef aFileName = getFileNameOfSpellingLoc(
compiler.getSourceManager().getSpellingLoc(methodDecl->getLocStart()));
compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(methodDecl)));
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/osl/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/comphelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/cppuhelper/"))
......@@ -96,12 +96,12 @@ bool FragileDestructor::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr
report(
DiagnosticsEngine::Warning,
"calling virtual method from destructor, either make the virtual method SAL_FINAL, or make this class SAL_FINAL",
callExpr->getLocStart())
compat::getBeginLoc(callExpr))
<< callExpr->getSourceRange();
report(
DiagnosticsEngine::Note,
"callee method here",
methodDecl->getLocStart())