compilerplugins/clang/redundantcast.cxx | 9 ++++++--- compilerplugins/clang/test/redundantcast.cxx | 10 +++++----- compilerplugins/clang/test/stringcopy.cxx | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-)
New commits: commit c855400e9686ddd8bcba5691393f839f6f52c966 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Jun 2 14:00:08 2017 +0200 Reduce loplugin:redundantcast warnings about functional casts even futher Change-Id: Ieae9b5c9c7c6d9b8459e5d163f55d8f5024adfae diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index 6d740ddca883..9604365dc945 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -539,9 +539,12 @@ bool RedundantCast::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * exp // // std::initializer_list<Foo>{bar, baz} // - // ), at least for now: + // ), and only to cases where the sub-expression already is a prvalue (and + // thus the cast is unlikely meant to create a temporary): auto const sub = compat::getSubExprAsWritten(expr); - if (isa<InitListExpr>(sub) || isa<CXXStdInitializerListExpr>(sub)) { + if (sub->getValueKind() != VK_RValue || isa<InitListExpr>(sub) + || isa<CXXStdInitializerListExpr>(sub)) + { return true; } @@ -580,7 +583,7 @@ bool RedundantCast::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * exp } auto const t1 = expr->getTypeAsWritten(); - auto const t2 = compat::getSubExprAsWritten(expr)->getType(); + auto const t2 = sub->getType(); if (t1 != t2) return true; if (!isOkToRemoveArithmeticCast(t1, t2, expr->getSubExpr())) diff --git a/compilerplugins/clang/test/redundantcast.cxx b/compilerplugins/clang/test/redundantcast.cxx index 1d2646a0f463..22130b32196c 100644 --- a/compilerplugins/clang/test/redundantcast.cxx +++ b/compilerplugins/clang/test/redundantcast.cxx @@ -143,12 +143,12 @@ void testStaticCast() { // non-class lvalue, non-const: int ni{}; (void) static_cast<int>(ni); // expected-error {{static_cast from 'int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}} - /* => */ (void) int(ni); //TODO: expected-error {{redundant functional cast from 'int' to 'int' [loplugin:redundantcast]}} + /* => */ (void) int(ni); (void) static_cast<int &>(ni); // expected-error {{static_cast from 'int' lvalue to 'int &' lvalue is redundant [loplugin:redundantcast]}} (void) static_cast<int &&>(ni); (void) static_cast<int const>(ni); // expected-error {{in static_cast from 'int' lvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}} /* => */ (void) static_cast<int>(ni); // expected-error {{static_cast from 'int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}} - /* => */ (void) int(ni); //TODO: expected-error {{redundant functional cast from 'int' to 'int' [loplugin:redundantcast]}} + /* => */ (void) int(ni); (void) static_cast<int const &>(ni); // expected-error {{static_cast from 'int' lvalue to 'const int &' lvalue should be written as const_cast [loplugin:redundantcast]}} /* => */ (void) const_cast<int const &>(ni); (void) static_cast<int const &&>(ni); // expected-error {{static_cast from 'int' lvalue to 'const int &&' xvalue should be written as const_cast [loplugin:redundantcast]}} @@ -168,7 +168,7 @@ void testStaticCast() { // non-class xvalue, non-const: (void) static_cast<int>(nix()); // expected-error {{static_cast from 'int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}} - /* => */ (void) int(nix()); //TODO: expected-error {{redundant functional cast from 'int' to 'int' [loplugin:redundantcast]}} + /* => */ (void) int(nix()); // (void) static_cast<int &>(nix()); (void) static_cast<int &&>(nix()); // expected-error {{static_cast from 'int' xvalue to 'int &&' xvalue is redundant [loplugin:redundantcast]}} (void) static_cast<int const>(nix()); // expected-error {{in static_cast from 'int' xvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}} @@ -209,7 +209,7 @@ void testStaticCast() { // class lvalue, non-const: S ns{}; (void) static_cast<S>(ns); // expected-error {{static_cast from 'S' lvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}} - /* => */ (void) S(ns); //TODO: expected-error {{redundant functional cast from 'S' to 'S' [loplugin:redundantcast]}} + /* => */ (void) S(ns); (void) static_cast<S &>(ns); // expected-error {{static_cast from 'S' lvalue to 'S &' lvalue is redundant [loplugin:redundantcast]}} (void) static_cast<S &&>(ns); (void) static_cast<S const>(ns); // expected-error {{static_cast from 'S' lvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}} @@ -232,7 +232,7 @@ void testStaticCast() { // class xvalue, non-const: (void) static_cast<S>(nsx()); // expected-error {{static_cast from 'S' xvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}} - /* => */ (void) S(nsx()); //TODO: expected-error {{redundant functional cast from 'S' to 'S' [loplugin:redundantcast]}} + /* => */ (void) S(nsx()); // (void) static_cast<S &>(nsx()); (void) static_cast<S &&>(nsx()); // expected-error {{static_cast from 'S' xvalue to 'S &&' xvalue is redundant [loplugin:redundantcast]}} (void) static_cast<S const>(nsx()); // expected-error {{static_cast from 'S' xvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}} diff --git a/compilerplugins/clang/test/stringcopy.cxx b/compilerplugins/clang/test/stringcopy.cxx index 01d10ceef833..c801b7096f74 100644 --- a/compilerplugins/clang/test/stringcopy.cxx +++ b/compilerplugins/clang/test/stringcopy.cxx @@ -13,7 +13,7 @@ int main() { OUString s; - (void) OUString(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'rtl::OUString' [loplugin:stringcopy]}} expected-error {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantcast]}} + (void) OUString(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'rtl::OUString' [loplugin:stringcopy]}} using T1 = OUString; (void) T1(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'T1' (aka 'rtl::OUString') [loplugin:stringcopy]}} using T2 = OUString const; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits