diff options
author | Noel <noelgrandin@gmail.com> | 2020-11-25 08:14:07 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-11-30 12:32:14 +0100 |
commit | 8332d6d8200e8ca1f22dd98d9373efd5a431d09c (patch) | |
tree | dd45d452202998297b8562743ea6345462304d04 /compilerplugins | |
parent | d05a4cfbdcece491f7385dbeaa7eca03f2fdc1d5 (diff) |
loplugin:stringviewparam include comparisons with string literals
Change-Id: I8ba1214500dddaf413c506a4b82f43d63cda804b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106559
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/stringviewparam.cxx | 15 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringviewparam.cxx | 10 |
2 files changed, 23 insertions, 2 deletions
diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx index 3056b6412930..365b2cf2a8a5 100644 --- a/compilerplugins/clang/stringviewparam.cxx +++ b/compilerplugins/clang/stringviewparam.cxx @@ -174,10 +174,21 @@ DeclRefExpr const* relevantCXXOperatorCallExpr(CXXOperatorCallExpr const* expr) } else if (compat::isComparisonOp(expr)) { + auto arg0 = compat::IgnoreImplicit(expr->getArg(0)); + if (isa<clang::StringLiteral>(arg0)) + { + return relevantDeclRefExpr(expr->getArg(1)); + } + auto arg1 = compat::IgnoreImplicit(expr->getArg(1)); + if (isa<clang::StringLiteral>(arg1)) + { + return relevantDeclRefExpr(expr->getArg(0)); + } + // TODO Can't currently convert rtl::OString because we end up with ambiguous operator== // (one in string_view header and one in rtl/string.hxx header) - auto st1 = relevantStringType(compat::IgnoreImplicit(expr->getArg(0))->getType()); - auto st2 = relevantStringType(compat::IgnoreImplicit(expr->getArg(1))->getType()); + auto st1 = relevantStringType(arg0->getType()); + auto st2 = relevantStringType(arg1->getType()); if (st1 == StringType::RtlOustring && st2 == StringType::RtlOustring) { auto e1 = relevantDeclRefExpr(expr->getArg(0)); diff --git a/compilerplugins/clang/test/stringviewparam.cxx b/compilerplugins/clang/test/stringviewparam.cxx index decd17408506..a9269dff3891 100644 --- a/compilerplugins/clang/test/stringviewparam.cxx +++ b/compilerplugins/clang/test/stringviewparam.cxx @@ -55,4 +55,14 @@ bool f7(const OUString& p1, OUString p2) { return p1 == p2; } // expected-error@+1 {{replace function parameter of type 'const rtl::OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}} bool f8(const OUString& p1, std::u16string_view p2) { return p1 == p2; } +struct Converter +{ + // expected-error@+1 {{replace function parameter of type 'const rtl::OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}} + static bool convertBool(bool& rBool, const OUString& rString) + { + rBool = rString == "true"; + return rBool || (rString == "false"); + } +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |