[PATCH] Use 'auto const&' for iterators whose deref operator returns a const var

Edwin Vane edwin.vane at intel.com
Tue May 7 12:30:43 PDT 2013


  Could you use clang-format on the code you added?


================
Comment at: cpp11-migrate/LoopConvert/LoopActions.cpp:1009
@@ +1008,3 @@
+                            Nodes.getNodeAs<CXXMemberCallExpr>(BeginCallName);
+    QualType CanonicalBeginType =
+               BeginCall->getMethodDecl()->getResultType().getCanonicalType();
----------------
assert(BeginCall != 0)

================
Comment at: cpp11-migrate/LoopConvert/LoopActions.cpp:1031
@@ +1030,3 @@
+                              Nodes.getNodeAs<QualType>(DerefByRefResultName)) {
+        // For user defined types if the reference pointee type is const
+        // qualified we add const.
----------------
I suggest replacing with:

A node will only be bound with DerefByRefResultName if we're dealing with a user-defined iterator type. Test the const qualification of the referenced type.

================
Comment at: cpp11-migrate/LoopConvert/LoopActions.cpp:1036
@@ +1035,3 @@
+      } else {
+        // In the built-in types case if the pointee type is const qualifed we
+        // add const.
----------------
I suggest replacing with:
By nature of the matcher, this case is triggered only for built-in iterator types (i.e. pointers). Test for const qualification of the pointed-at type.

================
Comment at: cpp11-migrate/LoopConvert/LoopActions.cpp:1038
@@ +1037,3 @@
+        // add const.
+        QualType InitPointeeType = CanonicalInitVarType->getPointeeType();
+        DerefByConstRef = InitPointeeType.isConstQualified();
----------------
Consider assert(isa<PointerType>(CanonicalInitVarType));


http://llvm-reviews.chandlerc.com/D759



More information about the cfe-commits mailing list