compilerplugins/clang/stringview.cxx | 7 +++++-- compilerplugins/clang/test/stringview.cxx | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-)
New commits: commit ff8d82dc4cc0841f11ad6d51d3ed37450a6f6971 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Wed Dec 9 22:44:49 2020 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Wed Dec 9 23:25:00 2020 +0100 Improve loplugin:stringview diagnostic messages Change-Id: If1b94de205fb9c1cc0491603f27073dfde67a485 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107511 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx index 26af817659be..abfc87f78fd6 100644 --- a/compilerplugins/clang/stringview.cxx +++ b/compilerplugins/clang/stringview.cxx @@ -143,6 +143,7 @@ bool StringView::VisitImplicitCastExpr(ImplicitCastExpr const* expr) void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr) { + bool charArg = false; auto const d = expr->getConstructor(); switch (d->getNumParams()) { @@ -153,6 +154,7 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr) auto const t = d->getParamDecl(0)->getType(); if (t->isAnyCharacterType()) { + charArg = true; break; } loplugin::TypeCheck tc(t); @@ -200,13 +202,14 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr) return; } report(DiagnosticsEngine::Warning, - "instead of an %0, pass a '%select{std::string_view|std::u16string_view}1'", + "instead of an %0, pass a '%select{std::string_view|std::u16string_view}1'" + "%select{| (or an '%select{rtl::OStringChar|rtl::OUStringChar}1')}2", expr->getExprLoc()) << expr->getType() << (loplugin::TypeCheck(expr->getType()).Class("OString").Namespace("rtl").GlobalNamespace() ? 0 : 1) - << expr->getSourceRange(); + << charArg << expr->getSourceRange(); } void StringView::handleCXXMemberCallExpr(CXXMemberCallExpr const* expr) diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx index 651e49e7bc27..d40ee50175a1 100644 --- a/compilerplugins/clang/test/stringview.cxx +++ b/compilerplugins/clang/test/stringview.cxx @@ -104,7 +104,7 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2) call_view(OString()); // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} call_view(OString("foo")); - // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' (or an 'rtl::OStringChar') [loplugin:stringview]}} call_view(OString(*s1)); // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} call_view(OString(s1)); @@ -123,7 +123,9 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2) call_view(OUString("foo")); // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} call_view(OUString(u"foo")); - // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' (or an 'rtl::OUStringChar') [loplugin:stringview]}} + call_view(OUString(*s1)); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' (or an 'rtl::OUStringChar') [loplugin:stringview]}} call_view(OUString(*s2)); // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} call_view(OUString(s2)); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits