diff --git a/compilerplugins/clang/pointerbool.cxx b/compilerplugins/clang/pointerbool.cxx index 66c6a04b3697..6886e1fac63f 100644 --- a/compilerplugins/clang/pointerbool.cxx +++ b/compilerplugins/clang/pointerbool.cxx @@ -38,12 +38,42 @@ public: TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + bool shouldVisitTemplateInstantiations() const { return true; } + + bool PreTraverseFunctionDecl(FunctionDecl* decl); + bool PostTraverseFunctionDecl(FunctionDecl* decl, bool); + bool TraverseFunctionDecl(FunctionDecl* decl); bool VisitCallExpr(CallExpr const*); private: llvm::Optional getCallValue(const Expr* arg); + std::vector functions_; }; +bool PointerBool::PreTraverseFunctionDecl(FunctionDecl* decl) +{ + functions_.push_back(decl); + return true; +} + +bool PointerBool::PostTraverseFunctionDecl(FunctionDecl*, bool) +{ + assert(!functions_.empty()); + functions_.pop_back(); + return true; +} + +bool PointerBool::TraverseFunctionDecl(FunctionDecl* decl) +{ + bool ret = true; + if (PreTraverseFunctionDecl(decl)) + { + ret = FilteringPlugin::TraverseFunctionDecl(decl); + PostTraverseFunctionDecl(decl, ret); + } + return ret; +} + bool PointerBool::VisitCallExpr(CallExpr const* callExpr) { if (ignoreLocation(callExpr)) @@ -98,6 +128,13 @@ bool PointerBool::VisitCallExpr(CallExpr const* callExpr) << arg->getSourceRange(); report(DiagnosticsEngine::Note, "method here", param->getLocation()) << param->getSourceRange(); + if (!functions_.empty()) + { + auto callerFD = functions_.back(); + if (callerFD->isTemplateInstantiation()) + report(DiagnosticsEngine::Note, "instantiated from here", + callerFD->getPointOfInstantiation()); + } } return true; } diff --git a/compilerplugins/clang/test/pointerbool.cxx b/compilerplugins/clang/test/pointerbool.cxx index 276a95ae1e00..fcb4a9a31b57 100644 --- a/compilerplugins/clang/test/pointerbool.cxx +++ b/compilerplugins/clang/test/pointerbool.cxx @@ -29,4 +29,18 @@ void test1(int* p1) func_bool(aSeq[0]); } +void func_bool2(bool); // expected-note {{method here [loplugin:pointerbool]}} + +template void func_bool_via_forward_template(Args&&... args) +{ + // expected-error@+1 {{possibly unwanted implicit conversion when calling bool param [loplugin:pointerbool]}} + func_bool2(std::forward(args)...); +} + +void test2(int p1) +{ + // expected-note@+1 {{instantiated from here [loplugin:pointerbool]}} + func_bool_via_forward_template(p1); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/oox/dump/dumperbase.hxx b/include/oox/dump/dumperbase.hxx index bfdacf53b42c..9be2b341ff48 100644 --- a/include/oox/dump/dumperbase.hxx +++ b/include/oox/dump/dumperbase.hxx @@ -366,7 +366,7 @@ void StringHelper::appendValue( OUStringBuffer& rStr, Type nData, FormatType eFm case FORMATTYPE_SHORTHEX: appendShortHex( rStr, nData ); break; case FORMATTYPE_BIN: appendBin( rStr, nData ); break; case FORMATTYPE_FIX: appendFix( rStr, nData ); break; - case FORMATTYPE_BOOL: appendBool( rStr, nData ); break; + case FORMATTYPE_BOOL: appendBool( rStr, static_cast(nData) ); break; // avoid loplugin:pointerbool warning default:; } }