[cfe-commits] r56095 - in /cfe/trunk: lib/Parse/ParseStmt.cpp test/SemaCXX/do-while-scope.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Wed Sep 10 21:46:46 PDT 2008


Author: akirtzidis
Date: Wed Sep 10 23:46:46 2008
New Revision: 56095

URL: http://llvm.org/viewvc/llvm-project?rev=56095&view=rev
Log:
Fix do-while scoping in C++.

Added:
    cfe/trunk/test/SemaCXX/do-while-scope.cpp
Modified:
    cfe/trunk/lib/Parse/ParseStmt.cpp

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=56095&r1=56094&r2=56095&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Wed Sep 10 23:46:46 2008
@@ -702,7 +702,13 @@
   // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
   // there is no compound stmt.  C90 does not have this clause. We only do this
   // if the body isn't a compound statement to avoid push/pop in common cases.
-  bool NeedsInnerScope = getLang().C99 && Tok.isNot(tok::l_brace);
+  //
+  // C++ 6.5p2:
+  // The substatement in an iteration-statement implicitly defines a local scope
+  // which is entered and exited each time through the loop.
+  //
+  bool NeedsInnerScope = (getLang().C99 || getLang().CPlusPlus) &&
+                         Tok.isNot(tok::l_brace);
   if (NeedsInnerScope) EnterScope(Scope::DeclScope);
   
   // Read the body statement.

Added: cfe/trunk/test/SemaCXX/do-while-scope.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/do-while-scope.cpp?rev=56095&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/do-while-scope.cpp (added)
+++ cfe/trunk/test/SemaCXX/do-while-scope.cpp Wed Sep 10 23:46:46 2008
@@ -0,0 +1,8 @@
+// RUN: clang -fsyntax-only -verify %s 
+
+void test() {
+  int x;
+  do
+    int x;
+  while (1);
+}





More information about the cfe-commits mailing list