diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-12-09 22:44:49 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-12-09 23:25:00 +0100 |
commit | ff8d82dc4cc0841f11ad6d51d3ed37450a6f6971 (patch) | |
tree | 066c7dfbfde6a3d72d28c8b6a641a56a4b7e596c /compilerplugins | |
parent | 8cfe270258d914e154b9db8b6ad02cd923984435 (diff) |
Improve loplugin:stringview diagnostic messages
Change-Id: If1b94de205fb9c1cc0491603f27073dfde67a485
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107511
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/stringview.cxx | 7 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringview.cxx | 6 |
2 files changed, 9 insertions, 4 deletions
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)); |