diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-10-08 14:48:39 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-10-10 13:46:22 +0200 |
commit | 0bf61855164af5751e78ca8626c10d604b1ab13b (patch) | |
tree | 4a6ef2e62a3737e0976db45c5249744765e63be9 /compilerplugins/clang/compat.hxx | |
parent | d4938dfcaf4f5fbcb5a576fe9425b6d62584122f (diff) |
Fix failure of loplugin:useuniqueptr with older compilers
...where CompilerTest_compilerplugins_clang failed in
compilerplugins/clang/test/useuniqueptr.cxx due to Foo24's
HTMLAttrs::const_iterator it = m_aSetAttrTab.begin();
and either the old compiler lacked Clang's recent
<https://reviews.llvm.org/D50666> "Fix Stmt::ignoreImplicit" (and the above
initialization expression happens to include a CXXBindTemporaryExpr, at least
with libstdc++), or an even older compiler was used in pre-C++17 mode, so the
above initialization expression happens to include an elidable CXXConstructExpr
copy constructor call.
Change-Id: I757a9ad76829e399b4fe2da1c82863909b8c9657
Reviewed-on: https://gerrit.libreoffice.org/61531
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/compat.hxx')
-rw-r--r-- | compilerplugins/clang/compat.hxx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index a83ed8688278..f2a8e2f10fe0 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -193,6 +193,45 @@ inline llvm::StringRef getImmediateMacroNameForDiagnostics( #endif } +inline clang::Expr const * IgnoreImplicit(clang::Expr const * expr) { +#if CLANG_VERSION >= 80000 + return expr->IgnoreImplicit(); +#else + using namespace clang; + // Copy from Clang's lib/AST/Stmt.cpp, including <https://reviews.llvm.org/D50666> "Fix + // Stmt::ignoreImplicit": + Stmt const *s = expr; + + Stmt const *lasts = nullptr; + + while (s != lasts) { + lasts = s; + + if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) + s = ewc->getSubExpr(); + + if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) + s = mte->GetTemporaryExpr(); + + if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) + s = bte->getSubExpr(); + + if (auto *ice = dyn_cast<ImplicitCastExpr>(s)) + s = ice->getSubExpr(); + } + + return static_cast<Expr const *>(s); +#endif +} + +inline bool CPlusPlus17(clang::LangOptions const & opts) { +#if CLANG_VERSION >= 60000 + return opts.CPlusPlus17; +#else + return opts.CPlusPlus1z; +#endif +} + // Work around <http://reviews.llvm.org/D22128>: // // SfxErrorHandler::GetClassString (svtools/source/misc/ehdl.cxx): |