compilerplugins/clang/stringviewparam.cxx | 55 +++++++++++++++++++++++++ compilerplugins/clang/test/stringviewparam.cxx | 12 +++++ 2 files changed, 67 insertions(+)
New commits: commit 94f6765d6ecc3145fa2d266231124003cf953118 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Tue Jan 12 15:53:36 2021 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Tue Jan 12 22:28:18 2021 +0100 Avoid loplugin:stringviewparam when there already is a string_view overload This avoids clang-cl > In file included from core/connectivity/source/drivers/ado/Aolevariant.cxx:20: > connectivity/source/inc\ado/Aolevariant.hxx(72,40): error: replace function parameter of type 'const rtl::OUString &' with 'std::u16string_view' [loplugin:stringviewparam] > OLEVariant(const OUString& us) > ~~~~~~~~~~~~~~~~^~ which would make that OLEVariant ctor overload redundant with the existing OLEVariant(std::u16string_view us); overload, but with the OUString overload gone, implicit conversions from OUString to OLEVariant would no longer work, e.g., > connectivity/source/drivers/ado/AColumn.cxx(184,76): error: no viable conversion from 'rtl::OUString' to 'const connectivity::ado::OLEVariant' > OTools::putValue(m_aColumn.get_Properties(), sAdoPropertyName, getString(rValue)); > ^~~~~~~~~~~~~~~~~ Change-Id: I92a5cc29d9fd2a5ff1a951f79df64879d0f71743 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109180 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx index a96d8cad4929..86ee7c21b393 100644 --- a/compilerplugins/clang/stringviewparam.cxx +++ b/compilerplugins/clang/stringviewparam.cxx @@ -206,6 +206,57 @@ SmallVector<DeclRefExpr const*, 2> relevantCXXOperatorCallExpr(CXXOperatorCallEx return {}; } +//TODO: current implementation is not at all general, just tests what we encounter in practice: +bool hasStringViewOverload(ParmVarDecl const* decl) +{ + auto const d1 = cast<FunctionDecl>(decl->getDeclContext()); + auto const ctx = d1->getDeclContext(); + if (!ctx->isLookupContext()) + { + return false; + } + auto const res = ctx->lookup(d1->getDeclName()); + auto const idx = decl->getFunctionScopeIndex(); + auto const n = d1->getNumParams(); + assert(n > idx); + for (auto i = res.begin(); i != res.end(); ++i) + { + auto const d2 = dyn_cast<FunctionDecl>(*i); + if (d2 == nullptr) + { + continue; + } + if (d2->getNumParams() != n) + { + continue; + } + auto match = true; + for (unsigned j = 0; j != n; ++j) + { + if (j == idx) + { + //TODO: check for exactly std::string_view or std::u16string_view: + if (!isStringView(d2->getParamDecl(j)->getType())) + { + match = false; + break; + } + } + else if (d1->getParamDecl(j)->getType().getCanonicalType() + != d2->getParamDecl(j)->getType().getCanonicalType()) + { + match = false; + break; + } + } + if (match) + { + return true; + } + } + return false; +} + class StringViewParam final : public loplugin::FunctionAddress<loplugin::FilteringPlugin<StringViewParam>> { @@ -439,6 +490,10 @@ private: { continue; } + if (hasStringViewOverload(i)) + { + continue; + } auto const t = relevantStringType(i->getType().getNonReferenceType()); assert(t != StringType::None); report(DiagnosticsEngine::Warning, diff --git a/compilerplugins/clang/test/stringviewparam.cxx b/compilerplugins/clang/test/stringviewparam.cxx index 56fadbea71cf..24dab18e0f9c 100644 --- a/compilerplugins/clang/test/stringviewparam.cxx +++ b/compilerplugins/clang/test/stringviewparam.cxx @@ -71,4 +71,16 @@ struct Converter } }; +void f9(std::u16string_view); +void f9(OUString const& s) { return f9(std::u16string_view(s)); } + +struct S10 +{ + S10(std::u16string_view); + S10(OUString const& s) + : S10(std::u16string_view(s)) + { + } +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits