Index: include/clang/Parse/Parser.h
===================================================================
--- include/clang/Parse/Parser.h	(revision 128185)
+++ include/clang/Parse/Parser.h	(working copy)
@@ -1103,7 +1103,8 @@
   bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
                                       ParsedType ObjectType,
                                       bool EnteringContext,
-                                      bool *MayBePseudoDestructor = 0);
+                                      bool *MayBePseudoDestructor = 0,
+                                      bool IsTypename = false);
 
   //===--------------------------------------------------------------------===//
   // C++ 5.2p1: C++ Casts
Index: lib/Parse/ParseExprCXX.cpp
===================================================================
--- lib/Parse/ParseExprCXX.cpp	(revision 128185)
+++ lib/Parse/ParseExprCXX.cpp	(working copy)
@@ -15,6 +15,7 @@
 #include "clang/Parse/Parser.h"
 #include "RAIIObjectsForParser.h"
 #include "clang/Sema/DeclSpec.h"
+#include "clang/Sema/Scope.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "llvm/Support/ErrorHandling.h"
 
@@ -60,7 +61,8 @@
 bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
                                             ParsedType ObjectType,
                                             bool EnteringContext,
-                                            bool *MayBePseudoDestructor) {
+                                            bool *MayBePseudoDestructor,
+                                            bool IsTypename) {
   assert(getLang().CPlusPlus &&
          "Call sites of this function should be guarded by checking for C++");
 
@@ -115,12 +117,20 @@
       }
     }
 
+    // Microsoft mode parser hack to be able to parse type dependent 
+    // template name without the "template" keyword.  
+    bool IsImplicitTemplate = getLang().Microsoft && IsTypename &&
+                              Tok.is(tok::identifier) &&
+                              NextToken().is(tok::less) &&
+                              (getCurScope()->getFlags() & Scope::DeclScope) &&
+                              (HasScopeSpecifier || ObjectType);
+    
     // nested-name-specifier:
     //   nested-name-specifier 'template'[opt] simple-template-id '::'
 
     // Parse the optional 'template' keyword, then make sure we have
     // 'identifier <' after it.
-    if (Tok.is(tok::kw_template)) {
+    if (Tok.is(tok::kw_template) || IsImplicitTemplate) {
       // If we don't have a scope specifier or an object type, this isn't a
       // nested-name-specifier, since they aren't allowed to start with
       // 'template'.
@@ -128,7 +138,9 @@
         break;
 
       TentativeParsingAction TPA(*this);
-      SourceLocation TemplateKWLoc = ConsumeToken();
+      SourceLocation TemplateKWLoc;
+      if (!IsImplicitTemplate)
+        TemplateKWLoc = ConsumeToken();
       
       UnqualifiedId TemplateName;
       if (Tok.is(tok::identifier)) {
Index: lib/Parse/Parser.cpp
===================================================================
--- lib/Parse/Parser.cpp	(revision 128185)
+++ lib/Parse/Parser.cpp	(working copy)
@@ -1036,7 +1036,8 @@
     //            simple-template-id
     SourceLocation TypenameLoc = ConsumeToken();
     CXXScopeSpec SS;
-    if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/ParsedType(), false))
+    if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/ParsedType(), false,
+                                       0, /*IsTypename=*/true))
       return true;
     if (!SS.isSet()) {
       Diag(Tok.getLocation(), diag::err_expected_qualified_after_typename);
Index: test/SemaTemplate/MicrosoftTemplateExtensions.cpp
===================================================================
--- test/SemaTemplate/MicrosoftTemplateExtensions.cpp	(revision 0)
+++ test/SemaTemplate/MicrosoftTemplateExtensions.cpp	(revision 0)
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
+
+template <class A>
+class C1 {
+public:
+  template <int B>
+  class Iterator {
+  };
+};
+ 
+template<class T>
+class C2  {
+  // template is optional in microsoft mode.
+  typename C1<T>:: /*template*/  Iterator<0> Mypos;
+};
+
+template <class T>
+void f(){
+  // template is optional in microsoft mode.
+  typename C1<T>:: /*template*/ Iterator<0> Mypos;
+}
+
+int main()
+{
+  f<int>();
+}
+
+
+
