From: Argyrios Kyrtzidis Date: Sun, 5 Oct 2008 15:50:46 +0000 (+0000) Subject: Disambiguate between a declaration or an expression, in the 'for-init-statement'... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbc70c019f7b7f9a256ee29dab5287ecc82c6553;p=clang Disambiguate between a declaration or an expression, in the 'for-init-statement' part of a 'for' statement. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57112 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index df5e59fda9..75f2e59645 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -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. diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 1f6eae1fc0..228bc4886c 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -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); diff --git a/test/SemaCXX/decl-expr-ambiguity.cpp b/test/SemaCXX/decl-expr-ambiguity.cpp index 7c274dea99..2e9514c054 100644 --- a/test/SemaCXX/decl-expr-ambiguity.cpp +++ b/test/SemaCXX/decl-expr-ambiguity.cpp @@ -12,6 +12,7 @@ void f() { typeof(int)(a,5)<