[PATCH] D40445: [C++17] Allow an empty expression in an if init statement

Nicolas Lesser via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 24 09:40:05 PST 2017


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())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40445.124223.patch
Type: text/x-patch
Size: 1150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171124/5c5e96ba/attachment.bin>


More information about the cfe-commits mailing list