[clang-tools-extra] r360787 - Revert [clang-tidy] modernize-loop-convert: impl const cast iter

Don Hinton via cfe-commits cfe-commits at lists.llvm.org
Wed May 15 10:36:55 PDT 2019


Author: dhinton
Date: Wed May 15 10:36:54 2019
New Revision: 360787

URL: http://llvm.org/viewvc/llvm-project?rev=360787&view=rev
Log:
Revert [clang-tidy] modernize-loop-convert: impl const cast iter

This reverts r360785 (git commit 42d28be802fe5beab18bc1a27f89894c0a290d44)

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
    clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst
    clang-tools-extra/trunk/docs/clang-tidy/index.rst
    clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=360787&r1=360786&r2=360787&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Wed May 15 10:36:54 2019
@@ -791,6 +791,11 @@ bool LoopConvertCheck::isConvertible(AST
               CanonicalBeginType->getPointeeType(),
               CanonicalInitVarType->getPointeeType()))
         return false;
+    } else if (!Context->hasSameType(CanonicalInitVarType,
+                                     CanonicalBeginType)) {
+      // Check for qualified types to avoid conversions from non-const to const
+      // iterator types.
+      return false;
     }
   } else if (FixerKind == LFK_PseudoArray) {
     // This call is required to obtain the container.

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst?rev=360787&r1=360786&r2=360787&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst Wed May 15 10:36:54 2019
@@ -253,15 +253,3 @@ below ends up being performed at the `sa
       flag = true;
     }
   }
-
-OpenMP
-^^^^^^
-
-As range-based for loops are only available since OpenMP 5, this check should
-not been used on code with a compatibility requirements of OpenMP prior to
-version 5. It is **intentional** that this check does not make any attempts to
-exclude incorrect diagnostics on OpenMP for loops prior to OpenMP 5.
-
-To prevent this check to be applied (and to break) OpenMP for loops but still be
-applied to non-OpenMP for loops the usage of ``NOLINT`` (see
-:ref:`clang-tidy-nolint`) on the specific for loops is recommended.

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=360787&r1=360786&r2=360787&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Wed May 15 10:36:54 2019
@@ -258,8 +258,6 @@ An overview of all the command-line opti
           value:           'some value'
       ...
 
-.. _clang-tidy-nolint:
-
 Suppressing Undesired Diagnostics
 =================================
 

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp?rev=360787&r1=360786&r2=360787&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp Wed May 15 10:36:54 2019
@@ -369,7 +369,7 @@ void f() {
     // CHECK-FIXES: for (auto Val_int_ptr : Val_int_ptrs)
   }
 
-  // This container uses an iterator where the dereference type is a typedef of
+  // This container uses an iterator where the derefence type is a typedef of
   // a reference type. Make sure non-const auto & is still used. A failure here
   // means canonical types aren't being tested.
   {
@@ -431,22 +431,19 @@ void different_type() {
   // CHECK-FIXES: for (auto P : *Ps)
   // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X);
 
+  // V.begin() returns a user-defined type 'iterator' which, since it's
+  // different from const_iterator, disqualifies these loops from
+  // transformation.
   dependent<int> V;
   for (dependent<int>::const_iterator It = V.begin(), E = V.end();
        It != E; ++It) {
     printf("Fibonacci number is %d\n", *It);
   }
-  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int It : V)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
 
   for (dependent<int>::const_iterator It(V.begin()), E = V.end();
        It != E; ++It) {
     printf("Fibonacci number is %d\n", *It);
   }
-  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int It : V)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
 }
 
 // Tests to ensure that an implicit 'this' is picked up as the container.

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp?rev=360787&r1=360786&r2=360787&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp Wed May 15 10:36:54 2019
@@ -776,20 +776,17 @@ void different_type() {
   // CHECK-FIXES: for (auto P : *Ps)
   // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X);
 
+  // V.begin() returns a user-defined type 'iterator' which, since it's
+  // different from const_iterator, disqualifies these loops from
+  // transformation.
   dependent<int> V;
   for (dependent<int>::const_iterator It = V.begin(); It != V.end(); ++It) {
     printf("Fibonacci number is %d\n", *It);
   }
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int It : V)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
 
   for (dependent<int>::const_iterator It(V.begin()); It != V.end(); ++It) {
     printf("Fibonacci number is %d\n", *It);
   }
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int It : V)
-  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
 }
 
 } // namespace SingleIterator
@@ -994,26 +991,18 @@ void iterators() {
   // CHECK-FIXES: for (int & I : Dep)
   // CHECK-FIXES-NEXT: auto H2 = [&]() { int R = I + 2; };
 
+  // FIXME: It doesn't work with const iterators.
   for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end();
        I != E; ++I)
     auto H3 = [I]() { int R = *I; };
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int I : Dep)
-  // CHECK-FIXES-NEXT: auto H3 = [&I]() { int R = I; };
 
   for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end();
        I != E; ++I)
     auto H4 = [&]() { int R = *I + 1; };
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int I : Dep)
-  // CHECK-FIXES-NEXT: auto H4 = [&]() { int R = I + 1; };
 
   for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end();
        I != E; ++I)
     auto H5 = [=]() { int R = *I; };
-  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int R : Dep)
-  // CHECK-FIXES-NEXT: auto H5 = [=]() { };
 }
 
 void captureByValue() {




More information about the cfe-commits mailing list