diff options
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/bufferadd.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/conditionalstring.cxx | 33 | ||||
-rw-r--r-- | compilerplugins/clang/elidestringvar.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/implicitboolconversion.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/stringadd.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/stringconcatliterals.cxx | 7 | ||||
-rw-r--r-- | compilerplugins/clang/test/conditionalstring.cxx | 11 | ||||
-rw-r--r-- | compilerplugins/clang/test/elidestringvar.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/test/staticvar.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringadd.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringconcatliterals.cxx | 5 |
11 files changed, 39 insertions, 40 deletions
diff --git a/compilerplugins/clang/bufferadd.cxx b/compilerplugins/clang/bufferadd.cxx index fd32d4874e64..bc8c7065b2a1 100644 --- a/compilerplugins/clang/bufferadd.cxx +++ b/compilerplugins/clang/bufferadd.cxx @@ -360,7 +360,7 @@ bool BufferAdd::isSideEffectFree(Expr const* expr) return true; // Expr::HasSideEffects does not like stuff that passes through OUStringLiteral auto dc2 = loplugin::DeclCheck(constructExpr->getConstructor()->getParent()); - if (dc2.Struct("OUStringLiteral").Namespace("rtl").GlobalNamespace()) + if (dc2.Class("OUStringLiteral").Namespace("rtl").GlobalNamespace()) return true; } @@ -368,7 +368,7 @@ bool BufferAdd::isSideEffectFree(Expr const* expr) if (auto functionalCastExpr = dyn_cast<CXXFunctionalCastExpr>(expr)) { auto tc = loplugin::TypeCheck(functionalCastExpr->getType()); - if (tc.Struct("OUStringLiteral").Namespace("rtl").GlobalNamespace()) + if (tc.Class("OUStringLiteral").Namespace("rtl").GlobalNamespace()) return isSideEffectFree(functionalCastExpr->getSubExpr()); } diff --git a/compilerplugins/clang/conditionalstring.cxx b/compilerplugins/clang/conditionalstring.cxx index 2d40c1b3aebf..bf6c196846dc 100644 --- a/compilerplugins/clang/conditionalstring.cxx +++ b/compilerplugins/clang/conditionalstring.cxx @@ -15,8 +15,8 @@ #include "compat.hxx" #include "plugin.hxx" -// Find uses of OUString in conditional expressions that could be rewritten as OUStringLiteral, as -// in +// Find uses of OUString in conditional expressions that could be rewritten as std::u16string_view, +// as in // // s += (b ? OUString("xy") : OUString(z"); @@ -73,11 +73,11 @@ public: return true; } //TODO: Instead of a hardcoded list of functions, check that `fn` has overloads taking - // OUString and OUStringLiteral, respectively (and operator + is even more complicated than - // that, going via ToStringHelper<OUStringLiteral> specialization; the getNumArgs checks for - // the various functions are meant to guard against the unlikely case that the affected - // parameters get defaulted in the future; overloaded operators cannot generally have - // defaulted parameters): + // OUString and std::u16string_view, respectively (and operator + is even more complicated + // than that, going via ToStringHelper<std::u16string_view> specialization; the getNumArgs + // checks for the various functions are meant to guard against the unlikely case that the + // affected parameters get defaulted in the future; overloaded operators cannot generally + // have defaulted parameters): loplugin::DeclCheck const dc(fn); if (dc.Operator(OO_Equal).Class("OUString").Namespace("rtl").GlobalNamespace()) { @@ -358,7 +358,7 @@ private: enum class Kind { OUStringFromLiteral, - OUStringLiteralOrVoid, + StringViewOrVoid, Other }; @@ -373,9 +373,11 @@ private: Kind getKind(Expr const* expr) { auto const tc = loplugin::TypeCheck(ignoreImplicit(expr)->getType()); - if (tc.Struct("OUStringLiteral").Namespace("rtl").GlobalNamespace() || tc.Void()) + if (tc.ClassOrStruct("basic_string_view").StdNamespace() //TODO: check explicitly for + // std::basic_string_view<char16_t> + || tc.Void()) { - return Kind::OUStringLiteralOrVoid; + return Kind::StringViewOrVoid; } if (loplugin::TypeCheck(expr->getType()) .Class("OUString") @@ -423,8 +425,7 @@ private: return; } auto const k2 = getKind(cond->getFalseExpr()); - if (k2 == Kind::Other - || (k1 == Kind::OUStringLiteralOrVoid && k2 == Kind::OUStringLiteralOrVoid)) + if (k2 == Kind::Other || (k1 == Kind::StringViewOrVoid && k2 == Kind::StringViewOrVoid)) { return; } @@ -432,20 +433,20 @@ private: { report(DiagnosticsEngine::Warning, ("replace both 2nd and 3rd operands of conditional expression with" - " `rtl::OUStringLiteral`"), + " `std::u16string_view`"), cond->getExprLoc()) << cond->getSourceRange(); } else { - assert((k1 == Kind::OUStringFromLiteral && k2 == Kind::OUStringLiteralOrVoid) - || (k1 == Kind::OUStringLiteralOrVoid && k2 == Kind::OUStringFromLiteral)); + assert((k1 == Kind::OUStringFromLiteral && k2 == Kind::StringViewOrVoid) + || (k1 == Kind::StringViewOrVoid && k2 == Kind::OUStringFromLiteral)); auto const second = k1 == Kind::OUStringFromLiteral; auto const sub = (second ? cond->getTrueExpr() : cond->getFalseExpr())->IgnoreParenImpCasts(); report(DiagnosticsEngine::Warning, ("replace %select{2nd|3rd}0 operand of conditional expression with" - " `rtl::OUStringLiteral`"), + " `std::u16string_view`"), sub->getExprLoc()) << (second ? 0 : 1) << sub->getSourceRange(); report(DiagnosticsEngine::Note, "conditional expression is here", cond->getExprLoc()) diff --git a/compilerplugins/clang/elidestringvar.cxx b/compilerplugins/clang/elidestringvar.cxx index 561e14c17a40..27b0e5ab77bd 100644 --- a/compilerplugins/clang/elidestringvar.cxx +++ b/compilerplugins/clang/elidestringvar.cxx @@ -125,7 +125,7 @@ public: { auto const e2 = e1->getArg(0); if (loplugin::TypeCheck(e2->getType()) - .Struct("OUStringLiteral") + .Class("OUStringLiteral") .Namespace("rtl") .GlobalNamespace()) { diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index 53da99518ff0..14db22788596 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -719,7 +719,7 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr( if (ignoreLocation(expr)) { return true; } - if (isBool(expr->getSubExprAsWritten()) && !isBool(expr)) { + if (isBool(compat::getSubExprAsWritten(expr)) && !isBool(expr)) { // Ignore NoOp from 'sal_Bool' (aka 'unsigned char') to 'const unsigned // char' in makeAny(b) with b of type sal_Bool: if (expr->getCastKind() != CK_NoOp) { diff --git a/compilerplugins/clang/stringadd.cxx b/compilerplugins/clang/stringadd.cxx index 288e19c95981..3410c2a6c436 100644 --- a/compilerplugins/clang/stringadd.cxx +++ b/compilerplugins/clang/stringadd.cxx @@ -330,7 +330,7 @@ bool StringAdd::isSideEffectFree(Expr const* expr) return true; // Expr::HasSideEffects does not like stuff that passes through OUStringLiteral auto dc2 = loplugin::DeclCheck(constructExpr->getConstructor()->getParent()); - if (dc2.Struct("OUStringLiteral").Namespace("rtl").GlobalNamespace()) + if (dc2.Class("OUStringLiteral").Namespace("rtl").GlobalNamespace()) return true; } @@ -338,7 +338,7 @@ bool StringAdd::isSideEffectFree(Expr const* expr) if (auto functionalCastExpr = dyn_cast<CXXFunctionalCastExpr>(expr)) { auto tc = loplugin::TypeCheck(functionalCastExpr->getType()); - if (tc.Struct("OUStringLiteral").Namespace("rtl").GlobalNamespace()) + if (tc.Class("OUStringLiteral").Namespace("rtl").GlobalNamespace()) return isSideEffectFree(functionalCastExpr->getSubExpr()); } diff --git a/compilerplugins/clang/stringconcatliterals.cxx b/compilerplugins/clang/stringconcatliterals.cxx index 509a10363c01..f82114199de8 100644 --- a/compilerplugins/clang/stringconcatliterals.cxx +++ b/compilerplugins/clang/stringconcatliterals.cxx @@ -27,7 +27,9 @@ Expr const * stripCtor(Expr const * expr) { return expr; } auto qt = loplugin::DeclCheck(e2->getConstructor()); - if (qt.MemberFunction().Class("OStringLiteral").Namespace("rtl").GlobalNamespace()) { + if (qt.MemberFunction().Class("OStringLiteral").Namespace("rtl").GlobalNamespace() + || qt.MemberFunction().Class("OUStringLiteral").Namespace("rtl").GlobalNamespace()) + { if (e2->getNumArgs() == 1) { return e2->getArg(0)->IgnoreParenImpCasts(); } @@ -36,8 +38,7 @@ Expr const * stripCtor(Expr const * expr) { if (!((qt.MemberFunction().Class("OString").Namespace("rtl") .GlobalNamespace()) || (qt.MemberFunction().Class("OUString").Namespace("rtl") - .GlobalNamespace()) - || qt.MemberFunction().Struct("OUStringLiteral").Namespace("rtl").GlobalNamespace())) + .GlobalNamespace()))) { return expr; } diff --git a/compilerplugins/clang/test/conditionalstring.cxx b/compilerplugins/clang/test/conditionalstring.cxx index f38bc1d2436f..c044ee324b50 100644 --- a/compilerplugins/clang/test/conditionalstring.cxx +++ b/compilerplugins/clang/test/conditionalstring.cxx @@ -13,17 +13,14 @@ void f(OUString s, bool b) { - // expected-error@+2 {{replace 2nd operand of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} + // expected-error@+2 {{replace 2nd operand of conditional expression with `std::u16string_view` [loplugin:conditionalstring]}} // expected-note@+1 {{conditional expression is here [loplugin:conditionalstring]}} s += (b ? OUString("a") : throw 0); - // expected-error@+2 {{replace 2nd operand of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} - // expected-note@+1 {{conditional expression is here [loplugin:conditionalstring]}} - s += (b ? OUString("a") : OUStringLiteral(u"b")); - // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} + // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `std::u16string_view` [loplugin:conditionalstring]}} b = (b ? ("x") : (OUString(("y")))) == s; - // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} + // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `std::u16string_view` [loplugin:conditionalstring]}} b = operator==(s, b ? OUString("x") : OUString("y")); - // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} + // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `std::u16string_view` [loplugin:conditionalstring]}} s.operator+=(b ? OUString("x") : OUString("y")); } diff --git a/compilerplugins/clang/test/elidestringvar.cxx b/compilerplugins/clang/test/elidestringvar.cxx index bc0de05c999e..1835c183bb39 100644 --- a/compilerplugins/clang/test/elidestringvar.cxx +++ b/compilerplugins/clang/test/elidestringvar.cxx @@ -18,8 +18,9 @@ OUString f(sal_Unicode c, int n) OUString s2('a'); // expected-note@+1 {{literal OUString variable defined here [loplugin:elidestringvar]}} OUString s3(u'a'); + static constexpr OUStringLiteral s4lit(u"a"); // expected-note@+1 {{literal OUString variable defined here [loplugin:elidestringvar]}} - OUString s4 = OUStringLiteral(u"a"); + OUString s4 = s4lit; switch (n) { case 1: diff --git a/compilerplugins/clang/test/staticvar.cxx b/compilerplugins/clang/test/staticvar.cxx index f527df6a521a..5c0a86fc420f 100644 --- a/compilerplugins/clang/test/staticvar.cxx +++ b/compilerplugins/clang/test/staticvar.cxx @@ -11,6 +11,8 @@ #include <sal/config.h> #include <rtl/ustring.hxx> +#include <string_view> + struct S1 { int x, y; @@ -52,13 +54,13 @@ S2 const& f3() // no warning expected struct S4 { - OUStringLiteral const cName; + std::u16string_view const cName; bool const bCanBeVisible; }; S4 const& f4() { static const S4 s1[] = { - { OUStringLiteral(u"/DocColor"), false }, + { std::u16string_view(u"/DocColor"), false }, }; return s1[0]; } diff --git a/compilerplugins/clang/test/stringadd.cxx b/compilerplugins/clang/test/stringadd.cxx index 0879805d3449..e17b207fcb64 100644 --- a/compilerplugins/clang/test/stringadd.cxx +++ b/compilerplugins/clang/test/stringadd.cxx @@ -18,7 +18,7 @@ namespace test1 { static const char XXX1[] = "xxx"; -static const char16_t XXX1u[] = u"xxx"; +static constexpr char16_t XXX1u[] = u"xxx"; static const char XXX2[] = "xxx"; void f1(OUString s1, int i, OString o) { diff --git a/compilerplugins/clang/test/stringconcatliterals.cxx b/compilerplugins/clang/test/stringconcatliterals.cxx index 348440f0ec4c..d19ebb97c1c3 100644 --- a/compilerplugins/clang/test/stringconcatliterals.cxx +++ b/compilerplugins/clang/test/stringconcatliterals.cxx @@ -20,7 +20,7 @@ void f(std::ostream& s1) { static constexpr char foo[] = "foo"; - static char16_t const foou[] = u"foo"; + static constexpr char16_t foou[] = u"foo"; s1 << "foo" << "foo"; // expected-error@-1 {{replace '<<' between string literals with juxtaposition}} @@ -37,9 +37,6 @@ void f(std::ostream& s1) s1 << "foo" << OUString(FOO); // expected-error@-1 {{replace '<<' between string literals with juxtaposition}} s1 << "foo" << OUString(foo); - s1 << "foo" << OUStringLiteral(u"foo"); //TODO: warn too, OUStringLiteral wrapped in OUString - s1 << "foo" << OUStringLiteral(FOOu); //TODO: warn too, OUStringLiteral wrapped in OUString - s1 << "foo" << OUStringLiteral(foou); OString s2; s2 = "foo" + OString("foo"); // expected-error@-1 {{replace '+' between string literals with juxtaposition}} |