]> granicus.if.org Git - clang/commitdiff
Fix do-while scoping in C++.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 11 Sep 2008 04:46:46 +0000 (04:46 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 11 Sep 2008 04:46:46 +0000 (04:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56095 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseStmt.cpp
test/SemaCXX/do-while-scope.cpp [new file with mode: 0644]

index 875634daa679912b7a33e10f7c6900ab75d37b82..c776bb6c15a1e00cc628e47ced713c63c2626e09 100644 (file)
@@ -702,7 +702,13 @@ Parser::StmtResult Parser::ParseDoStatement() {
   // 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.
diff --git a/test/SemaCXX/do-while-scope.cpp b/test/SemaCXX/do-while-scope.cpp
new file mode 100644 (file)
index 0000000..94a3116
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang -fsyntax-only -verify %s 
+
+void test() {
+  int x;\r
+  do\r
+    int x;\r
+  while (1);\r
+}