diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -353,8 +353,8 @@ if (CanBeForRangeDecl) { // Skip until we hit a ')', ';', or a ':' with no matching '?'. // The final case is a for range declaration, the rest are not. + unsigned QuestionColonDepth = 0; while (true) { - unsigned QuestionColonDepth = 0; P.SkipUntil({tok::r_paren, tok::semi, tok::question, tok::colon}, StopBeforeMatch); if (P.Tok.is(tok::question)) diff --git a/clang/test/CodeGenCXX/for-loop-init-ternary-operator-statement.cpp b/clang/test/CodeGenCXX/for-loop-init-ternary-operator-statement.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/for-loop-init-ternary-operator-statement.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -O3 -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: define{{.*}} i32 @_Z1fv() +int f() { + // CHECK: ret i32 1 + for (int i = 0; int x = i < 2 ? 1 : 0; i++) { + return x; + } +} diff --git a/clang/test/PCH/for-loop-init-ternary-operator-statement.cpp b/clang/test/PCH/for-loop-init-ternary-operator-statement.cpp new file mode 100644 --- /dev/null +++ b/clang/test/PCH/for-loop-init-ternary-operator-statement.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-pch -std=c++2a -o %t %s +// RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s + +int f() { + // CHECK: for (int i = 0; x; i++) { + for (int i = 0; int x = i < 2 ? 1 : 0; i++) { + return x; + } +} + diff --git a/clang/test/Parser/cxx2a-init-statement.cpp b/clang/test/Parser/cxx2a-init-statement.cpp --- a/clang/test/Parser/cxx2a-init-statement.cpp +++ b/clang/test/Parser/cxx2a-init-statement.cpp @@ -15,6 +15,8 @@ int A<0>::*arr2[3]; for (int n = 5; int A::*x : arr2) {} + for (int i = 0; int x = i < 2 ? 1 : 0; i++) {} + F (*arr3[3])(int); for (int n = 5; F (*p)(int n) : arr3) {} for (int n = 5; F (*p)(int (n)) : arr3) {}