Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiateDecl.cpp	(revision 224914)
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp	(working copy)
@@ -42,9 +42,6 @@
   if (!OldDecl->getQualifierLoc())
     return false;
 
-  assert((NewDecl->getFriendObjectKind() ||
-          !OldDecl->getLexicalDeclContext()->isDependentContext()) &&
-         "non-friend with qualified name defined in dependent context");
   Sema::ContextRAII SavedContext(
       SemaRef,
       const_cast<DeclContext *>(NewDecl->getFriendObjectKind()
Index: test/SemaTemplate/instantiate-scope.cpp
===================================================================
--- test/SemaTemplate/instantiate-scope.cpp	(revision 224914)
+++ test/SemaTemplate/instantiate-scope.cpp	(working copy)
@@ -28,3 +28,11 @@
   X<void>().f(0); // expected-note {{instantiation of}}
   X<void>::n = 1; // expected-note {{instantiation of}}
 }
+
+template <class T> void invalid_qualified_name(T i) {
+  struct B {
+    static int x; // expected-error {{static data member 'x' not allowed in local class}}
+  } B::x;
+}
+
+void h() { invalid_qualified_name(4); }
