danlark created this revision. danlark added a reviewer: rsmith. danlark requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fix ternary operator in for loop argument, it was by mistake not set as CanBeForRangeDecl and led to incorrect codegen. It fixes https://bugs.llvm.org/show_bug.cgi?id=50038. I don't have commit rights. Danila Kutenin. kutdan...@yandex.ru Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D102502 Files: clang/lib/Parse/ParseTentative.cpp clang/test/Parser/cxx2a-init-statement.cpp Index: clang/test/Parser/cxx2a-init-statement.cpp =================================================================== --- clang/test/Parser/cxx2a-init-statement.cpp +++ clang/test/Parser/cxx2a-init-statement.cpp @@ -15,6 +15,8 @@ int A<0>::*arr2[3]; for (int n = 5; int A<true ? 0 : 1>::*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) {} Index: clang/lib/Parse/ParseTentative.cpp =================================================================== --- clang/lib/Parse/ParseTentative.cpp +++ 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))
Index: clang/test/Parser/cxx2a-init-statement.cpp =================================================================== --- clang/test/Parser/cxx2a-init-statement.cpp +++ clang/test/Parser/cxx2a-init-statement.cpp @@ -15,6 +15,8 @@ int A<0>::*arr2[3]; for (int n = 5; int A<true ? 0 : 1>::*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) {} Index: clang/lib/Parse/ParseTentative.cpp =================================================================== --- clang/lib/Parse/ParseTentative.cpp +++ 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))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits