[PATCH] D80536: [clang-tidy][modernize-loop-convert] Make loop var type human readable

Zinovy Nis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 25 23:25:42 PDT 2020


zinovy.nis created this revision.
zinovy.nis added reviewers: angelgarcia, alexfh.
zinovy.nis added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
zinovy.nis edited the summary of this revision.

Without this patch

  for(std::set<int>::iterator it = s.begin(); ...)

is converted into

  for(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<int>>>::value_type i : s)

With this patch the output is as expected:

  for(int i : s)

Related bug: https://bugs.llvm.org/show_bug.cgi?id=36688


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80536

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h


Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h
@@ -40,13 +40,14 @@
 };
 
 struct T {
+  typedef int value_type;
   struct iterator {
-    int& operator*();
-    const int& operator*()const;
+    value_type &operator*();
+    const value_type &operator*() const;
     iterator& operator ++();
     bool operator!=(const iterator &other);
-    void insert(int);
-    int X;
+    void insert(value_type);
+    value_type X;
   };
   iterator begin();
   iterator end();
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -621,6 +621,7 @@
   QualType Type = Context->getAutoDeductType();
   if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType())
     Type = Descriptor.ElemType.getUnqualifiedType();
+  Type = Type.getDesugaredType(*Context);
 
   // If the new variable name is from the aliased variable, then the reference
   // type for the new variable should only be used if the aliased variable was


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80536.266108.patch
Type: text/x-patch
Size: 1434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200526/bb88b22e/attachment.bin>


More information about the cfe-commits mailing list