Rakete1111 created this revision. Rakete1111 added a project: clang. This fixes PR35381 <https://llvm.org/pr35381>.
https://reviews.llvm.org/D40445 Files: lib/Parse/ParseExprCXX.cpp test/CXX/stmt.stmt/stmt.select/p3.cpp Index: test/CXX/stmt.stmt/stmt.select/p3.cpp =================================================================== --- test/CXX/stmt.stmt/stmt.select/p3.cpp +++ test/CXX/stmt.stmt/stmt.select/p3.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++1z -verify %s -DCXX17 int f(); @@ -17,3 +18,18 @@ else int x; // expected-error{{redefinition of 'x'}} } + +#ifdef CXX17 +int initStatement() { + if (int I = 0; ++I == 1) + return I; + + int Var = 0; + if (Var + Var; Var == 0) + return Var; + + if (; true) + return 1; +} +#endif + Index: lib/Parse/ParseExprCXX.cpp =================================================================== --- lib/Parse/ParseExprCXX.cpp +++ lib/Parse/ParseExprCXX.cpp @@ -1745,6 +1745,11 @@ case ConditionOrInitStatement::Expression: { ProhibitAttributes(attrs); + // We can have an empty expression here. + // if (; true); + if (TryConsumeToken(tok::semi)) + return ParseCXXCondition(nullptr, Loc, CK); + // Parse the expression. ExprResult Expr = ParseExpression(); // expression if (Expr.isInvalid())
Index: test/CXX/stmt.stmt/stmt.select/p3.cpp =================================================================== --- test/CXX/stmt.stmt/stmt.select/p3.cpp +++ test/CXX/stmt.stmt/stmt.select/p3.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++1z -verify %s -DCXX17 int f(); @@ -17,3 +18,18 @@ else int x; // expected-error{{redefinition of 'x'}} } + +#ifdef CXX17 +int initStatement() { + if (int I = 0; ++I == 1) + return I; + + int Var = 0; + if (Var + Var; Var == 0) + return Var; + + if (; true) + return 1; +} +#endif + Index: lib/Parse/ParseExprCXX.cpp =================================================================== --- lib/Parse/ParseExprCXX.cpp +++ lib/Parse/ParseExprCXX.cpp @@ -1745,6 +1745,11 @@ case ConditionOrInitStatement::Expression: { ProhibitAttributes(attrs); + // We can have an empty expression here. + // if (; true); + if (TryConsumeToken(tok::semi)) + return ParseCXXCondition(nullptr, Loc, CK); + // Parse the expression. ExprResult Expr = ParseExpression(); // expression if (Expr.isInvalid())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits