Kaydet (Commit) 0bf61855 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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: 's avatarStephan Bergmann <sbergman@redhat.com>
üst d4938dfc
......@@ -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):
......
......@@ -278,7 +278,6 @@ class Foo23
}
};
#if CLANG_VERSION >= 60000
class Foo24
{
typedef std::vector<int*> HTMLAttrs;
......@@ -289,7 +288,6 @@ class Foo24
delete *it; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
}
};
#endif
// ------------------------------------------------------------------------------------------------
// tests for passing owning pointers to constructors
......
......@@ -495,12 +495,16 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
auto init = iterVarDecl->getInit();
if (init)
{
init = init->IgnoreImplicit();
init = compat::IgnoreImplicit(init);
if (!compat::CPlusPlus17(compiler.getLangOpts()))
if (auto x = dyn_cast<CXXConstructExpr>(init))
if (x->isElidable())
init = compat::IgnoreImplicit(x->getArg(0));
if (auto x = dyn_cast<CXXConstructExpr>(init))
if (x->getNumArgs() == 1
|| (x->getNumArgs() >= 2 && isa<CXXDefaultArgExpr>(x->getArg(1))))
{
init = x->getArg(0)->IgnoreImplicit();
init = compat::IgnoreImplicit(x->getArg(0));
}
if (auto x = dyn_cast<CXXMemberCallExpr>(init))
init = x->getImplicitObjectArgument();
......
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