[clang-tools-extra] r176690 - Extend loop variable naming checks

Edwin Vane edwin.vane at intel.com
Fri Mar 8 06:15:18 PST 2013


Author: revane
Date: Fri Mar  8 08:15:18 2013
New Revision: 176690

URL: http://llvm.org/viewvc/llvm-project?rev=176690&view=rev
Log:
Extend loop variable naming checks

The loop convert tests for conflicting names have been extended to check for
macro names, types, and language keywords including language extensions. Tests
have also been added.

Fixes PR15322

Author: Jack Yang <jack.yang at intel.com>
Reviewer: gribozavr, klimek, revane

Added:
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-alias.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-conflict.cpp
Removed:
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming.cpp
Modified:
    clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.cpp
    clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.cpp
    clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.h
    clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.cpp
    clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.h
    clang-tools-extra/trunk/test/cpp11-migrate/Combined/combined.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/array.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/confidence.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/dependency.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/iterator.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/nesting.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/pseudoarray.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/single-iterator.cpp

Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.cpp Fri Mar  8 08:15:18 2013
@@ -750,7 +750,7 @@ void LoopFixer::doConversion(ASTContext
     // was used exactly once - in the initialization of AliasVar.
   } else {
     VariableNamer Namer(GeneratedDecls, &ParentFinder->getStmtToParentStmtMap(),
-                        TheLoop, IndexVar, MaybeContainer);
+                        TheLoop, IndexVar, MaybeContainer, Context);
     VarName = Namer.createIndexName();
     // First, replace all usages of the array subscript expression with our new
     // variable.

Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.cpp Fri Mar  8 08:15:18 2013
@@ -115,3 +115,25 @@ bool DeclFinderASTVisitor::VisitDeclRefE
     return VisitNamedDecl(D);
   return true;
 }
+
+/// \brief If the new variable name conflicts with any type used in the loop,
+/// then we mark that variable name as taken.
+bool DeclFinderASTVisitor::VisitTypeLoc(TypeLoc TL) {
+  QualType QType = TL.getType();
+
+  // Check if our name conflicts with a type, to handle for typedefs.
+  if (QType.getAsString() == Name) {
+    Found = true;
+    return false;
+  }
+  // Check for base type conflicts. For example, when a struct is being
+  // referenced in the body of the loop, the above getAsString() will return the
+  // whole type (ex. "struct s"), but will be caught here.
+  if (const IdentifierInfo *Ident = QType.getBaseTypeIdentifier()) {
+    if (Ident->getName() == Name) {
+      Found = true;
+      return false;
+    }
+  }
+  return true;
+}

Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.h?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/StmtAncestor.h Fri Mar  8 08:15:18 2013
@@ -194,6 +194,7 @@ private:
   bool VisitForStmt(clang::ForStmt *F);
   bool VisitNamedDecl(clang::NamedDecl *D);
   bool VisitDeclRefExpr(clang::DeclRefExpr *D);
+  bool VisitTypeLoc(clang::TypeLoc TL);
 };
 
 #endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_STMT_ANCESTOR_H

Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.cpp Fri Mar  8 08:15:18 2013
@@ -57,12 +57,24 @@ std::string VariableNamer::createIndexNa
   return IteratorName;
 }
 
-/// \brief Determines whether or not the the name Symbol exists in LoopContext,
-/// any of its parent contexts, or any of its child statements.
+/// \brief Determines whether or not the the name \a Symbol conflicts with
+/// language keywords or defined macros. Also checks if the name exists in
+/// LoopContext, any of its parent contexts, or any of its child statements.
 ///
 /// We also check to see if the same identifier was generated by this loop
 /// converter in a loop nested within SourceStmt.
-bool VariableNamer::declarationExists(const StringRef Symbol) {
+bool VariableNamer::declarationExists(StringRef Symbol) {
+  assert(Context != 0 && "Expected an ASTContext");
+  IdentifierInfo &Ident = Context->Idents.get(Symbol);
+
+  // Check if the symbol is not an identifier (ie. is a keyword or alias).
+  if (!isAnyIdentifier(Ident.getTokenID()))
+    return true;
+
+  // Check for conflicting macro definitions.
+  if (Ident.hasMacroDefinition())
+    return true;
+
   // Determine if the symbol was generated in a parent context.
   for (const Stmt *S = SourceStmt; S != NULL; S = ReverseAST->lookup(S)) {
     StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(S);

Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.h?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/VariableNaming.h Fri Mar  8 08:15:18 2013
@@ -27,12 +27,13 @@
 /// index, if they exist.
 class VariableNamer {
  public:
-  VariableNamer(StmtGeneratedVarNameMap *GeneratedDecls,
-                const StmtParentMap *ReverseAST, const clang::Stmt *SourceStmt,
-                const clang::VarDecl *OldIndex,
-                const clang::VarDecl *TheContainer) :
-  GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST),
-  SourceStmt(SourceStmt), OldIndex(OldIndex), TheContainer(TheContainer) { }
+  VariableNamer(
+      StmtGeneratedVarNameMap *GeneratedDecls, const StmtParentMap *ReverseAST,
+      const clang::Stmt *SourceStmt, const clang::VarDecl *OldIndex,
+      const clang::VarDecl *TheContainer, const clang::ASTContext *Context)
+      : GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST),
+        SourceStmt(SourceStmt), OldIndex(OldIndex), TheContainer(TheContainer),
+        Context(Context) {}
 
   /// \brief Generate a new index name.
   ///
@@ -47,10 +48,11 @@ class VariableNamer {
   const clang::Stmt *SourceStmt;
   const clang::VarDecl *OldIndex;
   const clang::VarDecl *TheContainer;
+  const clang::ASTContext *Context;
 
   // Determine whether or not a declaration that would conflict with Symbol
   // exists in an outer context or in any statement contained in SourceStmt.
-  bool declarationExists(const llvm::StringRef Symbol);
+  bool declarationExists(llvm::StringRef Symbol);
 };
 
 #endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H

Modified: clang-tools-extra/trunk/test/cpp11-migrate/Combined/combined.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/Combined/combined.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/Combined/combined.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/Combined/combined.cpp Fri Mar  8 08:15:18 2013
@@ -28,8 +28,8 @@ void test_loopconvert_and_nullptr_iterat
     *it = NULL;
   }
 
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : t)
-  // CHECK-NEXT: [[VAR]] = nullptr;
+  // CHECK: for (auto & elem : t)
+  // CHECK-NEXT: elem = nullptr;
 }
 
 void test_loopconvert_and_nullptr_risky() {
@@ -40,6 +40,6 @@ void test_loopconvert_and_nullptr_risky(
     (*pArr)[i] = NULL;
   }
 
-  // RISKY: for (auto & [[VAR:[a-z_]+]] : *pArr)
-  // RISKY-NEXT: [[VAR:[a-z_]+]] = nullptr;
+  // RISKY: for (auto & elem : *pArr)
+  // RISKY-NEXT: elem = nullptr;
 }

Modified: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/array.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/array.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/array.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/array.cpp Fri Mar  8 08:15:18 2013
@@ -25,8 +25,8 @@ void f() {
     sum += arr[i];
     int k;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
-  // CHECK-NEXT: sum += [[VAR]];
+  // CHECK: for (auto & elem : arr) {
+  // CHECK-NEXT: sum += elem;
   // CHECK-NEXT: int k;
   // CHECK-NEXT: }
 
@@ -34,68 +34,68 @@ void f() {
     printf("Fibonacci number is %d\n", arr[i]);
     sum += arr[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & elem : arr)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
+  // CHECK-NEXT: sum += elem + 2;
 
   for (int i = 0; i < N; ++i) {
     int x = arr[i];
     int y = arr[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: int x = [[VAR]];
-  // CHECK-NEXT: int y = [[VAR]] + 2;
+  // CHECK: for (auto & elem : arr)
+  // CHECK-NEXT: int x = elem;
+  // CHECK-NEXT: int y = elem + 2;
 
   for (int i = 0; i < N; ++i) {
     int x = N;
     x = arr[i];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
+  // CHECK: for (auto & elem : arr)
   // CHECK-NEXT: int x = N;
-  // CHECK-NEXT: x = [[VAR]];
+  // CHECK-NEXT: x = elem;
 
   for (int i = 0; i < N; ++i) {
     arr[i] += 1;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
-  // CHECK-NEXT: [[VAR]] += 1;
+  // CHECK: for (auto & elem : arr) {
+  // CHECK-NEXT: elem += 1;
   // CHECK-NEXT: }
 
   for (int i = 0; i < N; ++i) {
     int x = arr[i] + 2;
     arr[i] ++;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: int x = [[VAR]] + 2;
-  // CHECK-NEXT: [[VAR]] ++;
+  // CHECK: for (auto & elem : arr)
+  // CHECK-NEXT: int x = elem + 2;
+  // CHECK-NEXT: elem ++;
 
   for (int i = 0; i < N; ++i) {
     arr[i] = 4 + arr[i];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: [[VAR]] = 4 + [[VAR]];
+  // CHECK: for (auto & elem : arr)
+  // CHECK-NEXT: elem = 4 + elem;
 
   for (int i = 0; i < NMinusOne + 1; ++i) {
     sum += arr[i];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
-  // CHECK-NEXT: sum += [[VAR]];
+  // CHECK: for (auto & elem : arr) {
+  // CHECK-NEXT: sum += elem;
   // CHECK-NEXT: }
 
   for (int i = 0; i < N; ++i) {
     printf("Fibonacci number %d has address %p\n", arr[i], &arr[i]);
     sum += arr[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: printf("Fibonacci number %d has address %p\n", [[VAR]], &[[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & elem : arr)
+  // CHECK-NEXT: printf("Fibonacci number %d has address %p\n", elem, &elem);
+  // CHECK-NEXT: sum += elem + 2;
 
   Val teas[N];
   for (int i = 0; i < N; ++i) {
     teas[i].g();
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : teas) {
-  // CHECK-NEXT: [[VAR]].g();
+  // CHECK: for (auto & tea : teas) {
+  // CHECK-NEXT: tea.g();
   // CHECK-NEXT: }
 }
 
@@ -106,15 +106,15 @@ struct HasArr {
     for (int i = 0; i < N; ++i) {
       printf("%d", Arr[i]);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr) {
-    // CHECK-NEXT: printf("%d", [[VAR]]);
+    // CHECK: for (auto & elem : Arr) {
+    // CHECK-NEXT: printf("%d", elem);
     // CHECK-NEXT: }
 
     for (int i = 0; i < N; ++i) {
       printf("%d", ValArr[i].x);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : ValArr) {
-    // CHECK-NEXT: printf("%d", [[VAR]].x);
+    // CHECK: for (auto & elem : ValArr) {
+    // CHECK-NEXT: printf("%d", elem.x);
     // CHECK-NEXT: }
   }
 
@@ -122,15 +122,15 @@ struct HasArr {
     for (int i = 0; i < N; ++i) {
       printf("%d", this->Arr[i]);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : this->Arr) {
-    // CHECK-NEXT: printf("%d", [[VAR]]);
+    // CHECK: for (auto & elem : this->Arr) {
+    // CHECK-NEXT: printf("%d", elem);
     // CHECK-NEXT: }
 
     for (int i = 0; i < N; ++i) {
       printf("%d", this->ValArr[i].x);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : this->ValArr) {
-    // CHECK-NEXT: printf("%d", [[VAR]].x);
+    // CHECK: for (auto & elem : this->ValArr) {
+    // CHECK-NEXT: printf("%d", elem.x);
     // CHECK-NEXT: }
   }
 };
@@ -150,6 +150,6 @@ void memberFunctionPointer() {
   void (Val::*mfpArr[N])(void) = { &Val::g };
   for (int i = 0; i < N; ++i)
     (v.*mfpArr[i])();
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : mfpArr)
-  // CHECK-NEXT: (v.*[[VAR]])();
+  // CHECK: for (auto & elem : mfpArr)
+  // CHECK-NEXT: (v.*elem)();
 }

Modified: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/confidence.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/confidence.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/confidence.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/confidence.cpp Fri Mar  8 08:15:18 2013
@@ -19,15 +19,15 @@ void f() {
   // CHECK: for (int i = 0; i < M; ++i) {
   // CHECK-NEXT: sum += Arr[0][i];
   // CHECK-NEXT: }
-  // RISKY: for (auto & [[VAR:[a-z_]+]] : Arr[0]) {
-  // RISKY-NEXT: sum += [[VAR]];
+  // RISKY: for (auto & elem : Arr[0]) {
+  // RISKY-NEXT: sum += elem;
   // RISKY-NEXT: }
 
   for (int i = 0; i < N; ++i) {
     sum += (*pArr)[i];
   }
-  // RISKY: for (auto & [[VAR:[a-z_]+]] : *pArr) {
-  // RISKY-NEXT: sum += [[VAR]];
+  // RISKY: for (auto & elem : *pArr) {
+  // RISKY-NEXT: sum += elem;
   // RISKY-NEXT: }
   // CHECK: for (int i = 0; i < N; ++i) {
   // CHECK-NEXT: sum += (*pArr)[i];

Modified: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/dependency.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/dependency.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/dependency.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/dependency.cpp Fri Mar  8 08:15:18 2013
@@ -10,9 +10,9 @@ void f() {
     int a = 0;
     int b = arr[i][a];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
+  // CHECK: for (auto & elem : arr) {
   // CHECK-NEXT: int a = 0;
-  // CHECK-NEXT: int b = [[VAR]][a];
+  // CHECK-NEXT: int b = elem[a];
   // CHECK-NEXT: }
 
   for (int j = 0; j < M; ++j) {

Modified: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/iterator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/iterator.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/iterator.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/iterator.cpp Fri Mar  8 08:15:18 2013
@@ -12,95 +12,95 @@ void f() {
   for (T::iterator it = t.begin(), e = t.end(); it != e; ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : t)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : t)
+  // CHECK-NEXT: printf("I found %d\n", elem);
 
   T *pt;
   for (T::iterator it = pt->begin(), e = pt->end(); it != e; ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : *pt)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : *pt)
+  // CHECK-NEXT: printf("I found %d\n", elem);
 
   S s;
   for (S::const_iterator it = s.begin(), e = s.end(); it != e; ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: printf("s has value %d\n", (elem).x);
 
   S *ps;
   for (S::const_iterator it = ps->begin(), e = ps->end(); it != e; ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : *ps)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & p : *ps)
+  // CHECK-NEXT: printf("s has value %d\n", (p).x);
 
   for (S::const_iterator it = s.begin(), e = s.end(); it != e; ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: printf("s has value %d\n", elem.x);
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
     it->x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].x = 3;
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: elem.x = 3;
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
     (*it).x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: ([[VAR]]).x = 3;
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: (elem).x = 3;
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
     it->nonConstFun(4, 5);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].nonConstFun(4, 5);
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: elem.nonConstFun(4, 5);
 
   U u;
   for (U::iterator it = u.begin(), e = u.end(); it != e; ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & elem : u)
+  // CHECK-NEXT: printf("s has value %d\n", elem.x);
 
   for (U::iterator it = u.begin(), e = u.end(); it != e; ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & elem : u)
+  // CHECK-NEXT: printf("s has value %d\n", (elem).x);
 
   U::iterator A;
   for (U::iterator i = u.begin(), e = u.end(); i != e; ++i)
     int k = A->x + i->x;
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: int k = A->x + [[VAR]].x;
+  // CHECK: for (auto & elem : u)
+  // CHECK-NEXT: int k = A->x + elem.x;
 
   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: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
 
   for (dependent<int>::const_iterator it(v.begin()), e = v.end();
        it != e; ++it) {
     printf("Fibonacci number is %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
 
   doublyDependent<int,int> intmap;
   for (doublyDependent<int,int>::iterator it = intmap.begin(), e = intmap.end();
        it != e; ++it) {
     printf("intmap[%d] = %d", it->first, it->second);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : intmap)
-  // CHECK-NEXT: printf("intmap[%d] = %d", [[VAR]].first, [[VAR]].second);
+  // CHECK: for (auto & elem : intmap)
+  // CHECK-NEXT: printf("intmap[%d] = %d", elem.first, elem.second);
 
   // PtrSet's iterator dereferences by value so auto & can't be used.
   {

Added: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-alias.cpp?rev=176690&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-alias.cpp (added)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-alias.cpp Fri Mar  8 08:15:18 2013
@@ -0,0 +1,59 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -loop-convert %t.cpp -- -I %S/Inputs
+// RUN: FileCheck -input-file=%t.cpp %s
+
+#include "structures.h"
+
+const int N = 10;
+
+Val Arr[N];
+Val &func(Val &);
+
+void aliasing() {
+  // If the loop container is only used for a declaration of a temporary
+  // variable to hold each element, we can name the new variable for the
+  // converted range-based loop as the temporary variable's name.
+
+  // In the following case, "t" is used as a temporary variable to hold each
+  // element, and thus we consider the name "t" aliased to the loop.
+  // The extra blank braces are left as a placeholder for after the variable
+  // declaration is deleted.
+  for (int i = 0; i < N; ++i) {
+    Val &t = Arr[i]; { }
+    int y = t.x;
+  }
+  // CHECK: for (auto & t : Arr)
+  // CHECK-NOT: Val &{{[a-z_]+}} =
+  // CHECK-NEXT: { }
+  // CHECK-NEXT: int y = t.x;
+
+  // The container was not only used to initialize a temporary loop variable for
+  // the container's elements, so we do not alias the new loop variable.
+  for (int i = 0; i < N; ++i) {
+    Val &t = Arr[i];
+    int y = t.x;
+    int z = Arr[i].x + t.x;
+  }
+  // CHECK: for (auto & elem : Arr)
+  // CHECK-NEXT: Val &t = elem;
+  // CHECK-NEXT: int y = t.x;
+  // CHECK-NEXT: int z = elem.x + t.x;
+
+  for (int i = 0; i < N; ++i) {
+    Val t = Arr[i];
+    int y = t.x;
+    int z = Arr[i].x + t.x;
+  }
+  // CHECK: for (auto & elem : Arr)
+  // CHECK-NEXT: Val t = elem;
+  // CHECK-NEXT: int y = t.x;
+  // CHECK-NEXT: int z = elem.x + t.x;
+
+  for (int i = 0; i < N; ++i) {
+    Val &t = func(Arr[i]);
+    int y = t.x;
+  }
+  // CHECK: for (auto & elem : Arr)
+  // CHECK-NEXT: Val &t = func(elem);
+  // CHECK-NEXT: int y = t.x;
+}

Added: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-conflict.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-conflict.cpp?rev=176690&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-conflict.cpp (added)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming-conflict.cpp Fri Mar  8 08:15:18 2013
@@ -0,0 +1,111 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -loop-convert %t.cpp -- -I %S/Inputs
+// RUN: FileCheck -input-file=%t.cpp %s
+
+#include "structures.h"
+
+#define MAX(a,b) (a > b) ? a : b
+#define DEF 5
+
+const int N = 10;
+int nums[N];
+int sum = 0;
+
+namespace ns {
+  struct st {
+    int x;
+  };
+}
+
+void sameNames() {
+  int num = 0;
+  for (int i = 0; i < N; ++i) {
+    printf("Fibonacci number is %d\n", nums[i]);
+    sum += nums[i] + 2 + num;
+    (void) nums[i];
+  }
+  // CHECK: for (auto & nums_i : nums)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", nums_i);
+  // CHECK-NEXT: sum += nums_i + 2 + num;
+  // CHECK-NOT: (void) num;
+}
+
+void macroConflict() {
+  S MAXs;
+  for (S::const_iterator it = MAXs.begin(), e = MAXs.end(); it != e; ++it) {
+    printf("s has value %d\n", (*it).x);
+    printf("Max of 3 and 5: %d\n", MAX(3,5));
+  }
+  // CHECK: for (auto & MAXs_it : MAXs)
+  // CHECK-NEXT: printf("s has value %d\n", (MAXs_it).x);
+  // CHECK-NEXT: printf("Max of 3 and 5: %d\n", MAX(3,5));
+
+  T DEFs;
+  for (T::iterator it = DEFs.begin(), e = DEFs.end(); it != e; ++it) {
+    if (*it == DEF) {
+      printf("I found %d\n", *it);
+    }
+  }
+  // CHECK: for (auto & DEFs_it : DEFs)
+  // CHECK-NEXT: if (DEFs_it == DEF) {
+  // CHECK-NEXT: printf("I found %d\n", DEFs_it);
+}
+
+void keywordConflict() {
+  T ints;
+  for (T::iterator it = ints.begin(), e = ints.end(); it != e; ++it) {
+    *it = 5;
+  }
+  // CHECK: for (auto & ints_it : ints)
+  // CHECK-NEXT: ints_it = 5;
+
+  U __FUNCTION__s;
+  for (U::iterator it = __FUNCTION__s.begin(), e = __FUNCTION__s.end();
+       it != e; ++it) {
+    int __FUNCTION__s_it = (*it).x + 2;
+  }
+  // CHECK: for (auto & __FUNCTION__s_elem : __FUNCTION__s)
+  // CHECK-NEXT: int __FUNCTION__s_it = (__FUNCTION__s_elem).x + 2;
+}
+
+void typeConflict() {
+  T Vals;
+  // Using the name "Val", although it is the name of an existing struct, is
+  // safe in this loop since it will only exist within this scope.
+  for (T::iterator it = Vals.begin(), e = Vals.end(); it != e; ++it) {
+  }
+  // CHECK: for (auto & Val : Vals)
+
+  // We cannot use the name "Val" in this loop since there is a reference to
+  // it in the body of the loop.
+  for (T::iterator it = Vals.begin(), e = Vals.end(); it != e; ++it) {
+    *it = sizeof(Val);
+  }
+  // CHECK: for (auto & Vals_it : Vals)
+  // CHECK-NEXT: Vals_it = sizeof(Val);
+
+  typedef struct Val TD;
+  U TDs;
+  // Naming the variable "TD" within this loop is safe because the typedef
+  // was never used within the loop.
+  for (U::iterator it = TDs.begin(), e = TDs.end(); it != e; ++it) {
+  }
+  // CHECK: for (auto & TD : TDs)
+
+  // "TD" cannot be used in this loop since the typedef is being used.
+  for (U::iterator it = TDs.begin(), e = TDs.end(); it != e; ++it) {
+    TD V;
+    V.x = 5;
+  }
+  // CHECK: for (auto & TDs_it : TDs)
+  // CHECK-NEXT: TD V;
+  // CHECK-NEXT: V.x = 5;
+
+  using ns::st;
+  T sts;
+  for (T::iterator it = sts.begin(), e = sts.end(); it != e; ++it) {
+    *it = sizeof(st);
+  }
+  // CHECK: for (auto & sts_it : sts)
+  // CHECK-NEXT: sts_it = sizeof(st);
+}

Removed: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming.cpp?rev=176689&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/naming.cpp (removed)
@@ -1,67 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: cpp11-migrate -loop-convert %t.cpp -- -I %S/Inputs
-// RUN: FileCheck -input-file=%t.cpp %s
-
-#include "structures.h"
-
-const int N = 10;
-int nums[N];
-int sum = 0;
-
-Val Arr[N];
-Val &func(Val &);
-
-void aliasing() {
-  // The extra blank braces are left as a placeholder for after the variable
-  // declaration is deleted.
-  for (int i = 0; i < N; ++i) {
-    Val &t = Arr[i]; { }
-    int y = t.x;
-  }
-  // CHECK: for (auto & t : Arr)
-  // CHECK-NEXT: { }
-  // CHECK-NEXT: int y = t.x;
-
-  for (int i = 0; i < N; ++i) {
-    Val &t = Arr[i];
-    int y = t.x;
-    int z = Arr[i].x + t.x;
-  }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr)
-  // CHECK-NEXT: Val &t = [[VAR]];
-  // CHECK-NEXT: int y = t.x;
-  // CHECK-NEXT: int z = [[VAR]].x + t.x;
-
-  for (int i = 0; i < N; ++i) {
-    Val t = Arr[i];
-    int y = t.x;
-    int z = Arr[i].x + t.x;
-  }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr)
-  // CHECK-NEXT: Val t = [[VAR]];
-  // CHECK-NEXT: int y = t.x;
-  // CHECK-NEXT: int z = [[VAR]].x + t.x;
-
-  for (int i = 0; i < N; ++i) {
-    Val &t = func(Arr[i]);
-    int y = t.x;
-  }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr)
-  // CHECK-NEXT: Val &t = func([[VAR]]);
-  // CHECK-NEXT: int y = t.x;
-}
-
-void sameNames() {
-  int num = 0;
-  for (int i = 0; i < N; ++i) {
-    printf("Fibonacci number is %d\n", nums[i]);
-    sum += nums[i] + 2 + num;
-    (void) nums[i];
-  }
-  // CHECK: int num = 0;
-  // CHECK-NEXT: for (auto & [[VAR:[a-z_]+]] : nums)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2 + num;
-  // CHECK-NOT: (void) num;
-  // CHECK: }
-}

Modified: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/nesting.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/nesting.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/nesting.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/nesting.cpp Fri Mar  8 08:15:18 2013
@@ -16,10 +16,10 @@ void f() {
       int l = Arr[i].x + Arr[j].x;
     }
   }
-  // CHECK: for (auto & [[VAR:[a-zA-Z_]+]] : Arr)
-  // CHECK-NEXT: for (auto & [[INNERVAR:[a-zA-Z_]+]] : Arr)
-  // CHECK-NEXT: int k = [[VAR]].x + [[INNERVAR]].x;
-  // CHECK-NOT: int l = [[VAR]].x + [[VAR]].x;
+  // CHECK: for (auto & elem : Arr)
+  // CHECK-NEXT: for (auto & Arr_j : Arr)
+  // CHECK-NEXT: int k = elem.x + Arr_j.x;
+  // CHECK-NOT: int l = elem.x + elem.x;
 
   Val Nest[N][M];
   for (int i = 0; i < N; ++i) {
@@ -29,9 +29,9 @@ void f() {
   }
   // The inner loop is also convertible, but doesn't need to be converted
   // immediately. Update this test when that changes!
-  // CHECK: for (auto & [[VAR:[a-zA-Z_]+]] : Nest)
+  // CHECK: for (auto & elem : Nest)
   // CHECK-NEXT: for (int j = 0; j < M; ++j)
-  // CHECK-NEXT: printf("Got item %d", [[VAR]][j].x);
+  // CHECK-NEXT: printf("Got item %d", elem[j].x);
 
   // Note that the order of M and N are switched for this test.
   for (int j = 0; j < M; ++j) {
@@ -41,8 +41,8 @@ void f() {
   }
   // CHECK-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[i])
   // CHECK: for (int j = 0; j < M; ++j)
-  // CHECK-NEXT: for (auto & [[VAR:[a-zA-Z_]+]] : Nest)
-  // CHECK-NEXT: printf("Got item %d", [[VAR]][j].x);
+  // CHECK-NEXT: for (auto & elem : Nest)
+  // CHECK-NEXT: printf("Got item %d", elem[j].x);
   Nested<T> NestT;
   for (Nested<T>::iterator I = NestT.begin(), E = NestT.end(); I != E; ++I) {
     for (T::iterator TI = (*I).begin(), TE = (*I).end(); TI != TE; ++TI) {
@@ -51,7 +51,7 @@ void f() {
   }
   // The inner loop is also convertible, but doesn't need to be converted
   // immediately. Update this test when that changes!
-  // CHECK: for (auto & [[VAR:[a-zA-Z_]+]] : NestT) {
-  // CHECK-NEXT: for (T::iterator TI = ([[VAR]]).begin(), TE = ([[VAR]]).end(); TI != TE; ++TI) {
+  // CHECK: for (auto & elem : NestT) {
+  // CHECK-NEXT: for (T::iterator TI = (elem).begin(), TE = (elem).end(); TI != TE; ++TI) {
   // CHECK-NEXT: printf("%d", *TI);
 }

Modified: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/pseudoarray.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/pseudoarray.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/pseudoarray.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/pseudoarray.cpp Fri Mar  8 08:15:18 2013
@@ -15,25 +15,25 @@ void f() {
     printf("Fibonacci number is %d\n", v[i]);
     sum += v[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & elem : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
+  // CHECK-NEXT: sum += elem + 2;
 
   for (int i = 0, e = v.size(); i < e; ++i) {
     printf("Fibonacci number is %d\n", v.at(i));
     sum += v.at(i) + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & elem : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
+  // CHECK-NEXT: sum += elem + 2;
 
   for (int i = 0, e = pv->size(); i < e; ++i) {
     printf("Fibonacci number is %d\n", pv->at(i));
     sum += pv->at(i) + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : *pv)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & elem : *pv)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
+  // CHECK-NEXT: sum += elem + 2;
 
   // This test will fail if size() isn't called repeatedly, since it
   // returns unsigned int, and 0 is deduced to be signed int.
@@ -43,24 +43,24 @@ void f() {
     printf("Fibonacci number is %d\n", (*pv).at(i));
     sum += (*pv)[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : *pv)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & elem : *pv)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
+  // CHECK-NEXT: sum += elem + 2;
 
   for (int i = 0; i < cv->size(); ++i) {
     printf("Fibonacci number is %d\n", cv->at(i));
     sum += cv->at(i) + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : *cv)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & elem : *cv)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
+  // CHECK-NEXT: sum += elem + 2;
 }
 
 // Check for loops that don't mention containers
 void noContainer() {
   for (auto i = 0; i < v.size(); ++i) { }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v) { }
+  // CHECK: for (auto & elem : v) { }
 
   for (auto i = 0; i < v.size(); ++i) ;
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v) ;
+  // CHECK: for (auto & elem : v) ;
 }

Modified: clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/single-iterator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/single-iterator.cpp?rev=176690&r1=176689&r2=176690&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/single-iterator.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/LoopConvert/single-iterator.cpp Fri Mar  8 08:15:18 2013
@@ -12,9 +12,9 @@ void complexContainer() {
     MutableVal k = *i;
     MutableVal j = *i;
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : exes[index].getS())
-  // CHECK-NEXT: MutableVal k = [[VAR]];
-  // CHECK-NEXT: MutableVal j = [[VAR]];
+  // CHECK: for (auto & elem : exes[index].getS())
+  // CHECK-NEXT: MutableVal k = elem;
+  // CHECK-NEXT: MutableVal j = elem;
 }
 
 void f() {
@@ -23,93 +23,93 @@ void f() {
   for (T::iterator it = t.begin(); it != t.end(); ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : t)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : t)
+  // CHECK-NEXT: printf("I found %d\n", elem);
 
   T *pt;
   for (T::iterator it = pt->begin(); it != pt->end(); ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : *pt)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : *pt)
+  // CHECK-NEXT: printf("I found %d\n", elem);
 
   S s;
   for (S::const_iterator it = s.begin(); it != s.end(); ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: printf("s has value %d\n", (elem).x);
 
   S *ps;
   for (S::const_iterator it = ps->begin(); it != ps->end(); ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : *ps)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & p : *ps)
+  // CHECK-NEXT: printf("s has value %d\n", (p).x);
 
   for (S::const_iterator it = s.begin(); it != s.end(); ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: printf("s has value %d\n", elem.x);
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
     it->x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].x = 3;
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: elem.x = 3;
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
     (*it).x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: ([[VAR]]).x = 3;
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: (elem).x = 3;
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
     it->nonConstFun(4, 5);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].nonConstFun(4, 5);
+  // CHECK: for (auto & elem : s)
+  // CHECK-NEXT: elem.nonConstFun(4, 5);
 
   U u;
   for (U::iterator it = u.begin(); it != u.end(); ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & elem : u)
+  // CHECK-NEXT: printf("s has value %d\n", elem.x);
 
   for (U::iterator it = u.begin(); it != u.end(); ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & elem : u)
+  // CHECK-NEXT: printf("s has value %d\n", (elem).x);
 
   U::iterator A;
   for (U::iterator i = u.begin(); i != u.end(); ++i)
     int k = A->x + i->x;
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: int k = A->x + [[VAR]].x;
+  // CHECK: for (auto & elem : u)
+  // CHECK-NEXT: int k = A->x + elem.x;
 
   dependent<int> v;
   for (dependent<int>::const_iterator it = v.begin();
        it != v.end(); ++it) {
     printf("Fibonacci number is %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
 
   for (dependent<int>::const_iterator it(v.begin());
        it != v.end(); ++it) {
     printf("Fibonacci number is %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & elem : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", elem);
 
   doublyDependent<int,int> intmap;
   for (doublyDependent<int,int>::iterator it = intmap.begin();
        it != intmap.end(); ++it) {
     printf("intmap[%d] = %d", it->first, it->second);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : intmap)
-  // CHECK-NEXT: printf("intmap[%d] = %d", [[VAR]].first, [[VAR]].second);
+  // CHECK: for (auto & elem : intmap)
+  // CHECK-NEXT: printf("intmap[%d] = %d", elem.first, elem.second);
 }





More information about the cfe-commits mailing list