diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-06-21 12:14:08 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-06-25 13:53:21 +0200 |
commit | 4583911575edf98ccd5b15af8eafa6a3a7b64034 (patch) | |
tree | f3f33e53c45dd870f19e7e42db9bb5b4bf1f23bf /compilerplugins | |
parent | 1942182a3d1817bc539229d7fda3af69f7e295b8 (diff) |
improve loplugin:simplifyconstruct
Change-Id: If863d28c6db470faa0d22273020888d4219e069e
Reviewed-on: https://gerrit.libreoffice.org/74559
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/simplifyconstruct.cxx | 10 | ||||
-rw-r--r-- | compilerplugins/clang/test/simplifyconstruct.cxx | 10 |
2 files changed, 13 insertions, 7 deletions
diff --git a/compilerplugins/clang/simplifyconstruct.cxx b/compilerplugins/clang/simplifyconstruct.cxx index c3e28ce7bcda..55f2404f8ab1 100644 --- a/compilerplugins/clang/simplifyconstruct.cxx +++ b/compilerplugins/clang/simplifyconstruct.cxx @@ -87,19 +87,15 @@ bool SimplifyConstruct::VisitVarDecl(VarDecl const* varDecl) if (isa<AutoType>(varDecl->getType())) return true; - auto init = varDecl->getInit()->IgnoreImplicit(); - auto functionalCast = dyn_cast<CXXFunctionalCastExpr>(init); - if (!functionalCast) + auto init = varDecl->getInit(); + if (!isa<CXXFunctionalCastExpr>(init->IgnoreImplicit()) && !isa<CXXTemporaryObjectExpr>(init) + && !isa<CXXTemporaryObjectExpr>(init->IgnoreImplicit())) return true; // e.g. the LANGUAGE_DONTKNOW defines if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(init))) return true; - // varDecl->getInit()->IgnoreImplicit()->dump(); - // varDecl->getType()->dump(); - // varDecl->getType()->getUnqualifiedDesugaredType()->dump(); - report(DiagnosticsEngine::Warning, "simplify", varDecl->getLocation()) << varDecl->getSourceRange(); diff --git a/compilerplugins/clang/test/simplifyconstruct.cxx b/compilerplugins/clang/test/simplifyconstruct.cxx index 8fbffc8ba2d7..d44738f78d01 100644 --- a/compilerplugins/clang/test/simplifyconstruct.cxx +++ b/compilerplugins/clang/test/simplifyconstruct.cxx @@ -9,6 +9,7 @@ #include <memory> #include <rtl/ref.hxx> +#include <tools/gen.hxx> namespace test1 { @@ -75,4 +76,13 @@ struct Foo void f(Foo* f) { auto x = rtl::Reference(f); } } +namespace test5 +{ +void f() +{ + // expected-error@+1 {{simplify [loplugin:simplifyconstruct]}} + tools::Rectangle x = tools::Rectangle(10, 10, 10, 10); + (void)x; +} +} /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |