compilerplugins/clang/conststringvar.cxx | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
New commits: commit 6476745ac9a8cfba649a702a1a14af4526b65072 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Sun Feb 16 13:27:57 2020 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Sun Feb 16 14:17:12 2020 +0100 Fix loplugin:conststringvar ...after abc0344a234567aee0edcb4523036758d966481d "convert conststringvar plugin to shared infrastructre", causing errors like > [C ] cppuhelper/source/findsofficepath.c > Assertion failed: (Ctx.getLangOpts().CPlusPlus), function isCXX11ConstantExpr, file llvm/llvm-project/clang/lib/AST/ExprConstant.cpp, line 14567. > Stack dump: [...] > 6 libsystem_c.dylib 0x00007fff7266ca1c abort + 120 > 7 libsystem_c.dylib 0x00007fff7266bcd6 err + 0 > 8 clang 0x000000010b857ca3 clang::Expr::isCXX11ConstantExpr(clang::ASTContext const&, clang::APValue*, clang::SourceLocation*) const (.cold.2) + 35 > 9 clang 0x0000000109f7497e clang::Expr::isCXX11ConstantExpr(clang::ASTContext const&, clang::APValue*, clang::SourceLocation*) const + 1022 > 10 plugin.so 0x00000001182741ab loplugin::SharedRecursiveASTVisitorBasic::VisitVarDecl(clang::VarDecl*) + 1051 [...] > clang-11: error: clang frontend command failed due to signal (use -v to see invocation) Change-Id: I18c37dba294b0effd85bead8aa6e5679f77502d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88777 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/conststringvar.cxx b/compilerplugins/clang/conststringvar.cxx index c5e83722ac47..99cfb01c06f7 100644 --- a/compilerplugins/clang/conststringvar.cxx +++ b/compilerplugins/clang/conststringvar.cxx @@ -27,17 +27,24 @@ public: explicit ConstStringVar(loplugin::InstantiationData const & data): FilteringPlugin(data) {} + bool preRun() override { + return compiler.getLangOpts().CPlusPlus; + // clang::Expr::isCXX11ConstantExpr only works for C++ + } + + void postRun() override { + for (auto v: vars_) { + report( + DiagnosticsEngine::Warning, + "variable is only used as rvalue, should be const", + v->getLocation()) + << v->getSourceRange(); + } + } + void run() override { - if (compiler.getLangOpts().CPlusPlus) { - // clang::Expr::isCXX11ConstantExpr only works for C++ - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); - for (auto v: vars_) { - report( - DiagnosticsEngine::Warning, - "variable is only used as rvalue, should be const", - v->getLocation()) - << v->getSourceRange(); - } + if (preRun() && TraverseDecl(compiler.getASTContext().getTranslationUnitDecl())) { + postRun(); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits