]> granicus.if.org Git - clang/commitdiff
Disambiguate between a declaration or an expression, in the 'for-init-statement'...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 5 Oct 2008 15:50:46 +0000 (15:50 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 5 Oct 2008 15:50:46 +0000 (15:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57112 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Parse/ParseStmt.cpp
test/SemaCXX/decl-expr-ambiguity.cpp

index df5e59fda938ac1cdbaf6e21b15aab24c04fe7eb..75f2e596457f82abae12888787550fa7f57545c2 100644 (file)
@@ -590,6 +590,16 @@ private:
     return isDeclarationSpecifier();
   }
 
+  /// isSimpleDeclaration - Disambiguates between a declaration or an
+  /// expression, mainly used for the C 'clause-1' or the C++
+  // 'for-init-statement' part of a 'for' statement.
+  /// Returns true for declaration, false for expression.
+  bool isSimpleDeclaration() {
+    if (getLang().CPlusPlus)
+      return isCXXSimpleDeclaration();
+    return isDeclarationSpecifier();
+  }
+
   /// isCXXDeclarationStatement - C++-specialized function that disambiguates
   /// between a declaration or an expression statement, when parsing function
   /// bodies. Returns true for declaration, false for expression.
index 1f6eae1fc0601e9920376a86da247b05c526d281..228bc4886caf061eb11ea0e2c04d85be29b28ba9 100644 (file)
@@ -813,7 +813,7 @@ Parser::StmtResult Parser::ParseForStatement() {
   if (Tok.is(tok::semi)) {  // for (;
     // no first part, eat the ';'.
     ConsumeToken();
-  } else if (isDeclarationSpecifier()) {  // for (int X = 4;
+  } else if (isSimpleDeclaration()) {  // for (int X = 4;
     // Parse declaration, which eats the ';'.
     if (!C99orCXX)   // Use of C99-style for loops in C90 mode?
       Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
index 7c274dea99309f29f9cea86c9921f96c17a26bd1..2e9514c054e7a2f2d219775ce3f4018943b67c31 100644 (file)
@@ -12,6 +12,7 @@ void f() {
   typeof(int)(a,5)<<a; // expected-error {{function-style cast to a builtin type can only take one argument}}
   void(a), ++a; // expected-warning {{statement was disambiguated as expression}} expected-warning {{expression result unused}}
   if (int(a)+1) {}
+  for (int(a)+1;;) {}
 
   // Declarations.
   T(*d)(int(p)); // expected-warning {{statement was disambiguated as declaration}} expected-error {{previous definition is here}}