Index: test/Parser/2011-09-20-UsingTypenameIdentifiers.cpp
===================================================================
--- test/Parser/2011-09-20-UsingTypenameIdentifiers.cpp	(revision 0)
+++ test/Parser/2011-09-20-UsingTypenameIdentifiers.cpp	(revision 0)
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template< int mydim, typename Traits >
+class BasicGeometry
+{
+typedef int some_type_t;
+};
+
+template<class ctype, int mydim, int coorddim>
+class MockGeometry : BasicGeometry<mydim, int>{
+using typename BasicGeometry<mydim, int>::operator[]; // expected-error {{typename is allowed for identifiers only}}
+};
+
+int main() {
+   return 0;
+}
Index: include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- include/clang/Basic/DiagnosticParseKinds.td	(revision 140239)
+++ include/clang/Basic/DiagnosticParseKinds.td	(working copy)
@@ -225,6 +225,9 @@
   "type name does not allow storage class to be specified">;
 def err_typename_invalid_functionspec : Error<
   "type name does not allow function specifier to be specified">;
+def err_typename_identifiers_only : Error<
+  "typename is allowed for identifiers only">;
+  
 def err_invalid_decl_spec_combination : Error<
   "cannot combine with previous '%0' declaration specifier">;
 def err_invalid_vector_decl_spec_combination : Error<
Index: lib/Parse/ParseDeclCXX.cpp
===================================================================
--- lib/Parse/ParseDeclCXX.cpp	(revision 140239)
+++ lib/Parse/ParseDeclCXX.cpp	(working copy)
@@ -433,12 +433,14 @@
                                     Decl **OwnedType) {
   CXXScopeSpec SS;
   SourceLocation TypenameLoc;
+  SourceLocation TypenameEndLoc;
   bool IsTypeName;
 
   // Ignore optional 'typename'.
   // FIXME: This is wrong; we should parse this as a typename-specifier.
   if (Tok.is(tok::kw_typename)) {
     TypenameLoc = Tok.getLocation();
+    TypenameEndLoc = TypenameLoc.getLocWithOffset(Tok.getLength());
     ConsumeToken();
     IsTypeName = true;
   }
@@ -545,6 +547,15 @@
     return 0;
   }
 
+  // "typename" keyword is allowed for identifiers only,
+  // because it may be a type definition.
+  if (IsTypeName && Name.getKind() != UnqualifiedId::IK_Identifier) {
+    Diag(Name.getSourceRange().getBegin(), diag::err_typename_identifiers_only)
+      << FixItHint::CreateRemoval(SourceRange(TypenameLoc, TypenameEndLoc));
+    // Proceed parsing, but reset the IsTypeName flag.
+    IsTypeName = false;
+  }
+
   if (IsAliasDecl) {
     TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams;
     MultiTemplateParamsArg TemplateParamsArg(Actions,
