Restore patch I reversed in r138040. Known buildbot
failures are resolved.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138234 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index 7c38857..f6a79e5 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -52,7 +52,10 @@
                              SourceLocation InlineLoc) {
   assert(Tok.is(tok::kw_namespace) && "Not a namespace!");
   SourceLocation NamespaceLoc = ConsumeToken();  // eat the 'namespace'.
-
+  Decl *DC = getObjCDeclContext();
+  if (DC)
+    Actions.ActOnObjCContainerFinishDefinition(DC);
+    
   if (Tok.is(tok::code_completion)) {
     Actions.CodeCompleteNamespaceDecl(getCurScope());
     ConsumeCodeCompletionToken();
@@ -89,8 +92,10 @@
     if (InlineLoc.isValid())
       Diag(InlineLoc, diag::err_inline_namespace_alias)
           << FixItHint::CreateRemoval(InlineLoc);
-
-    return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
+    Decl *Res = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
+    if (DC)
+      Actions.ActOnObjCContainerStartDefinition(DC);
+    return Res;
   }
 
 
@@ -101,6 +106,8 @@
     }
     Diag(Tok, Ident ? diag::err_expected_lbrace :
          diag::err_expected_ident_lbrace);
+    if (DC)
+      Actions.ActOnObjCContainerStartDefinition(DC);
     return 0;
   }
 
@@ -115,6 +122,8 @@
     }
     Diag(LBrace, diag::err_namespace_nonnamespace_scope);
     SkipUntil(tok::r_brace, false);
+    if (DC)
+      Actions.ActOnObjCContainerStartDefinition(DC);
     return 0;
   }
 
@@ -173,6 +182,8 @@
   Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc);
 
   DeclEnd = RBraceLoc;
+  if (DC)
+    Actions.ActOnObjCContainerStartDefinition(DC);
   return NamespcDecl;
 }
 
@@ -317,7 +328,9 @@
                                              ParsedAttributesWithRange &attrs,
                                                Decl **OwnedType) {
   assert(Tok.is(tok::kw_using) && "Not using token");
-
+  Decl *DC = getObjCDeclContext();
+  if (DC)
+    Actions.ActOnObjCContainerFinishDefinition(DC);
   // Eat 'using'.
   SourceLocation UsingLoc = ConsumeToken();
 
@@ -335,7 +348,10 @@
         << R << FixItHint::CreateRemoval(R);
     }
 
-    return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
+    Decl *Res = ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
+    if (DC)
+      Actions.ActOnObjCContainerStartDefinition(DC);
+    return Res;
   }
 
   // Otherwise, it must be a using-declaration or an alias-declaration.
@@ -343,8 +359,11 @@
   // Using declarations can't have attributes.
   ProhibitAttributes(attrs);
 
-  return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
-                               AS_none, OwnedType);
+  Decl *Res = ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
+                                    AS_none, OwnedType);
+  if (DC)
+    Actions.ActOnObjCContainerStartDefinition(DC);
+  return Res;
 }
 
 /// ParseUsingDirective - Parse C++ using-directive, assumes