diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-30 12:16:31 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-31 08:25:07 +0200 |
commit | c9253818ec8252169c20450b41878be459568d95 (patch) | |
tree | 1f271151725042f33c3c8aa3988343bcd7f89e12 /compilerplugins | |
parent | 242a796a71e29a1d8cdc4dd71d2465b898db32ab (diff) |
loplugin:oncevar
extend oncevar to any POD type
Change-Id: Ia98ee0a67f183e40fb0c38477760124b2c411dc0
Reviewed-on: https://gerrit.libreoffice.org/40564
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/oncevar.cxx | 23 | ||||
-rw-r--r-- | compilerplugins/clang/test/oncevar.cxx | 6 |
2 files changed, 17 insertions, 12 deletions
diff --git a/compilerplugins/clang/oncevar.cxx b/compilerplugins/clang/oncevar.cxx index 00ecb1b6003a..052a448b0325 100644 --- a/compilerplugins/clang/oncevar.cxx +++ b/compilerplugins/clang/oncevar.cxx @@ -114,6 +114,9 @@ public: // macros managing to generate to a valid warning if (fn == SRCDIR "/solenv/bin/concat-deps.c") return; + // TODO bug in the plugin + if (fn == SRCDIR "/vcl/unx/generic/app/saldisp.cxx") + return; TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); @@ -220,6 +223,9 @@ public: if (loplugin::TypeCheck(qt).LvalueReference().NonConst()) { recordIgnore(expr->getArg(i)); } + if (loplugin::TypeCheck(qt).Pointer().NonConst()) { + recordIgnore(expr->getArg(i)); + } } } } @@ -235,6 +241,9 @@ public: if (loplugin::TypeCheck(qt).LvalueReference().NonConst()) { recordIgnore(expr->getArg(i)); } + if (loplugin::TypeCheck(qt).Pointer().NonConst()) { + recordIgnore(expr->getArg(i)); + } } } return true; @@ -321,9 +330,7 @@ bool OnceVar::VisitVarDecl( const VarDecl* varDecl ) return true; } auto const tc = loplugin::TypeCheck(varDecl->getType()); - if (!varDecl->getType()->isScalarType() - && !varDecl->getType()->isBooleanType() - && !varDecl->getType()->isEnumeralType() + if (!varDecl->getType().isCXX11PODType(compiler.getASTContext()) && !tc.Class("OString").Namespace("rtl").GlobalNamespace() && !tc.Class("OUString").Namespace("rtl").GlobalNamespace() && !tc.Class("OStringBuffer").Namespace("rtl").GlobalNamespace() @@ -346,22 +353,14 @@ bool OnceVar::VisitVarDecl( const VarDecl* varDecl ) if (auto e = dyn_cast<ExprWithCleanups>(initExpr)) { initExpr = e->getSubExpr(); } - if (auto stringLit = dyn_cast<clang::StringLiteral>(initExpr)) { + if (isa<clang::StringLiteral>(initExpr)) { foundStringLiteral = true; - // ignore long literals, helps to make the code more legible - if (stringLit->getLength() > 40) { - return true; - } } else if (auto constructExpr = dyn_cast<CXXConstructExpr>(initExpr)) { if (constructExpr->getNumArgs() == 0) { foundStringLiteral = true; // i.e., empty string } else { auto stringLit2 = dyn_cast<clang::StringLiteral>(constructExpr->getArg(0)); foundStringLiteral = stringLit2 != nullptr; - // ignore long literals, helps to make the code more legible - if (stringLit2 && stringLit2->getLength() > 40) { - return true; - } } } if (!foundStringLiteral) { diff --git a/compilerplugins/clang/test/oncevar.cxx b/compilerplugins/clang/test/oncevar.cxx index 5e01d1b98a21..c8cc7bc1390d 100644 --- a/compilerplugins/clang/test/oncevar.cxx +++ b/compilerplugins/clang/test/oncevar.cxx @@ -24,6 +24,9 @@ template<typename T> void f() { } template void f<int>(); // needed for clang-cl +class Foo; +void method1(const Foo**); + int main() { /* TODO int i; @@ -55,6 +58,9 @@ int main() { call_ref(s3); OUString const s4("xxx"); call_value(s4); + + const Foo* pInternalArgs[] = { nullptr }; + method1(pInternalArgs); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |