[clang-tools-extra] r259196 - [clang-tidy] Fix style issues. NFC

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 29 07:21:45 PST 2016


Author: alexfh
Date: Fri Jan 29 09:21:43 2016
New Revision: 259196

URL: http://llvm.org/viewvc/llvm-project?rev=259196&view=rev
Log:
[clang-tidy] Fix style issues. NFC

Added:
    clang-tools-extra/trunk/test/clang-tidy/performance-implicit-cast-in-loop.cpp
      - copied, changed from r259195, clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp
Removed:
    clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/performance/ImplicitCastInLoopCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/performance/ImplicitCastInLoopCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/ImplicitCastInLoopCheck.cpp?rev=259196&r1=259195&r2=259196&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/ImplicitCastInLoopCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/ImplicitCastInLoopCheck.cpp Fri Jan 29 09:21:43 2016
@@ -36,8 +36,7 @@ bool IsNonTrivialImplicitCast(const Stmt
 }
 } // namespace
 
-void ImplicitCastInLoopCheck::registerMatchers(
-    ast_matchers::MatchFinder* Finder) {
+void ImplicitCastInLoopCheck::registerMatchers(MatchFinder *Finder) {
   // We look for const ref loop variables that (optionally inside an
   // ExprWithCleanup) materialize a temporary, and contain a implicit cast. The
   // check on the implicit cast is done in check() because we can't access
@@ -57,28 +56,25 @@ void ImplicitCastInLoopCheck::registerMa
       this);
 }
 
-void ImplicitCastInLoopCheck::check(
-    const ast_matchers::MatchFinder::MatchResult &Result) {
+void ImplicitCastInLoopCheck::check(const MatchFinder::MatchResult &Result) {
   const auto* VD = Result.Nodes.getNodeAs<VarDecl>("faulty-var");
   const auto* Init = Result.Nodes.getNodeAs<Expr>("init");
   const auto* OperatorCall =
       Result.Nodes.getNodeAs<CXXOperatorCallExpr>("operator-call");
 
-  if (const auto* Cleanup = dyn_cast<ExprWithCleanups>(Init)) {
+  if (const auto* Cleanup = dyn_cast<ExprWithCleanups>(Init))
     Init = Cleanup->getSubExpr();
-  }
+
   const auto* Materialized = dyn_cast<MaterializeTemporaryExpr>(Init);
-  if (!Materialized) {
+  if (!Materialized)
     return;
-  }
 
   // We ignore NoOp casts. Those are generated if the * operator on the
   // iterator returns a value instead of a reference, and the loop variable
   // is a reference. This situation is fine (it probably produces the same
   // code at the end).
-  if (IsNonTrivialImplicitCast(Materialized->getTemporary())) {
+  if (IsNonTrivialImplicitCast(Materialized->getTemporary()))
     ReportAndFix(Result.Context, VD, OperatorCall);
-  }
 }
 
 void ImplicitCastInLoopCheck::ReportAndFix(

Copied: clang-tools-extra/trunk/test/clang-tidy/performance-implicit-cast-in-loop.cpp (from r259195, clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-implicit-cast-in-loop.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/performance-implicit-cast-in-loop.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp&r1=259195&r2=259196&rev=259196&view=diff
==============================================================================
    (empty)

Removed: clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp?rev=259195&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/performance_implicit_cast_in_loop.cpp (removed)
@@ -1,161 +0,0 @@
-// RUN: %check_clang_tidy %s performance-implicit-cast-in-loop %t
-
-// ---------- Classes used in the tests ----------
-
-// Iterator returning by value.
-template <typename T>
-struct Iterator {
-  void operator++();
-  T operator*();
-  bool operator!=(const Iterator& other);
-};
-
-// Iterator returning by reference.
-template <typename T>
-struct RefIterator {
-  void operator++();
-  T& operator*();
-  bool operator!=(const RefIterator& other);
-};
-
-// The template argument is an iterator type, and a view is an object you can
-// run a for loop on.
-template <typename T>
-struct View {
-  T begin();
-  T end();
-};
-
-// With this class, the implicit cast is a call to the (implicit) constructor of
-// the class.
-template <typename T>
-class ImplicitWrapper {
- public:
-  // Implicit!
-  ImplicitWrapper(const T& t);
-};
-
-// With this class, the implicit cast is a call to the conversion operators of
-// SimpleClass and ComplexClass.
-template <typename T>
-class OperatorWrapper {
- public:
-  explicit OperatorWrapper(const T& t);
-};
-
-struct SimpleClass {
-  int foo;
-  operator OperatorWrapper<SimpleClass>();
-};
-
-// The materialize expression is not the same when the class has a destructor,
-// so we make sure we cover that case too.
-class ComplexClass {
- public:
-  ComplexClass();
-  ~ComplexClass();
-  operator OperatorWrapper<ComplexClass>();
-};
-
-typedef View<Iterator<SimpleClass>> SimpleView;
-typedef View<RefIterator<SimpleClass>> SimpleRefView;
-typedef View<Iterator<ComplexClass>> ComplexView;
-typedef View<RefIterator<ComplexClass>> ComplexRefView;
-
-// ---------- The test themselves ----------
-// For each test we do, in the same order, const ref, non const ref, const
-// value, non const value.
-
-void SimpleClassIterator() {
-  for (const SimpleClass& foo : SimpleView()) {}
-  // This line does not compile because a temporary cannot be assigned to a non
-  // const reference.
-  // for (SimpleClass& foo : SimpleView()) {}
-  for (const SimpleClass foo : SimpleView()) {}
-  for (SimpleClass foo : SimpleView()) {}
-}
-
-void SimpleClassRefIterator() {
-  for (const SimpleClass& foo : SimpleRefView()) {}
-  for (SimpleClass& foo : SimpleRefView()) {}
-  for (const SimpleClass foo : SimpleRefView()) {}
-  for (SimpleClass foo : SimpleRefView()) {}
-}
-
-void ComplexClassIterator() {
-  for (const ComplexClass& foo : ComplexView()) {}
-  // for (ComplexClass& foo : ComplexView()) {}
-  for (const ComplexClass foo : ComplexView()) {}
-  for (ComplexClass foo : ComplexView()) {}
-}
-
-void ComplexClassRefIterator() {
-  for (const ComplexClass& foo : ComplexRefView()) {}
-  for (ComplexClass& foo : ComplexRefView()) {}
-  for (const ComplexClass foo : ComplexRefView()) {}
-  for (ComplexClass foo : ComplexRefView()) {}
-}
-
-void ImplicitSimpleClassIterator() {
-  for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit cast; you can either change the type to the correct one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value [performance-implicit-cast-in-loop]
-  // for (ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
-  for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
-  for (ImplicitWrapper<SimpleClass>foo : SimpleView()) {}
-}
-
-void ImplicitSimpleClassRefIterator() {
-  for (const ImplicitWrapper<SimpleClass>& foo : SimpleRefView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
-  // for (ImplicitWrapper<SimpleClass>& foo : SimpleRefView()) {}
-  for (const ImplicitWrapper<SimpleClass> foo : SimpleRefView()) {}
-  for (ImplicitWrapper<SimpleClass>foo : SimpleRefView()) {}
-}
-
-void ImplicitComplexClassIterator() {
-  for (const ImplicitWrapper<ComplexClass>& foo : ComplexView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
-  // for (ImplicitWrapper<ComplexClass>& foo : ComplexView()) {}
-  for (const ImplicitWrapper<ComplexClass> foo : ComplexView()) {}
-  for (ImplicitWrapper<ComplexClass>foo : ComplexView()) {}
-}
-
-void ImplicitComplexClassRefIterator() {
-  for (const ImplicitWrapper<ComplexClass>& foo : ComplexRefView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
-  // for (ImplicitWrapper<ComplexClass>& foo : ComplexRefView()) {}
-  for (const ImplicitWrapper<ComplexClass> foo : ComplexRefView()) {}
-  for (ImplicitWrapper<ComplexClass>foo : ComplexRefView()) {}
-}
-
-void OperatorSimpleClassIterator() {
-  for (const OperatorWrapper<SimpleClass>& foo : SimpleView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
-  // for (OperatorWrapper<SimpleClass>& foo : SimpleView()) {}
-  for (const OperatorWrapper<SimpleClass> foo : SimpleView()) {}
-  for (OperatorWrapper<SimpleClass>foo : SimpleView()) {}
-}
-
-void OperatorSimpleClassRefIterator() {
-  for (const OperatorWrapper<SimpleClass>& foo : SimpleRefView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
-  // for (OperatorWrapper<SimpleClass>& foo : SimpleRefView()) {}
-  for (const OperatorWrapper<SimpleClass> foo : SimpleRefView()) {}
-  for (OperatorWrapper<SimpleClass>foo : SimpleRefView()) {}
-}
-
-void OperatorComplexClassIterator() {
-  for (const OperatorWrapper<ComplexClass>& foo : ComplexView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
-  // for (OperatorWrapper<ComplexClass>& foo : ComplexView()) {}
-  for (const OperatorWrapper<ComplexClass> foo : ComplexView()) {}
-  for (OperatorWrapper<ComplexClass>foo : ComplexView()) {}
-}
-
-void OperatorComplexClassRefIterator() {
-  for (const OperatorWrapper<ComplexClass>& foo : ComplexRefView()) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
-  // for (OperatorWrapper<ComplexClass>& foo : ComplexRefView()) {}
-  for (const OperatorWrapper<ComplexClass> foo : ComplexRefView()) {}
-  for (OperatorWrapper<ComplexClass>foo : ComplexRefView()) {}
-}




More information about the cfe-commits mailing list