Index: gcc/testsuite/g++.dg/template/using18.C
===================================================================
--- gcc/testsuite/g++.dg/template/using18.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/using18.C	(revision 0)
@@ -0,0 +1,31 @@
+// PR c++/23211
+// { dg-do compile }
+
+template<class T>
+struct foo 
+{
+  typedef int jtype;
+  struct bar 
+  {
+    using typename foo<T>::jtype; // { dg-error "not a base type" }
+    using foo<T>::jtype; // { dg-error "not a base type" }
+  };
+};
+
+template <class T>
+struct A : T
+{
+    using T::i;
+    using typename T::type;
+};
+
+struct B1 {};
+template <class T> struct B2 {};
+
+template <class T>
+struct C : B1, B2<T>
+{
+    using B1::x; // { dg-error "no member" }
+    using B2<T>::y;
+    using typename B2<T>::type;
+};
Index: gcc/testsuite/g++.dg/template/nested3.C
===================================================================
--- gcc/testsuite/g++.dg/template/nested3.C	(revision 182410)
+++ gcc/testsuite/g++.dg/template/nested3.C	(working copy)
@@ -24,7 +24,7 @@ class B {
 
 
 int main() {
-  B<char> objB; // { dg-message "required" }
+  B<char> objB;
 
   return 0;
 }
Index: gcc/testsuite/g++.dg/template/crash13.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash13.C	(revision 182410)
+++ gcc/testsuite/g++.dg/template/crash13.C	(working copy)
@@ -15,4 +15,4 @@ template <typename T> struct C
     X::Y;			// { dg-error "not a base type" }
 };
 
-C<void> c;			// { dg-message "required" }
+C<void> c;
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 182410)
+++ gcc/cp/parser.c	(working copy)
@@ -14971,12 +14971,12 @@ cp_parser_using_declaration (cp_parser*
 	  /* Create the USING_DECL.  */
 	  decl = do_class_using_decl (parser->scope, identifier);
 
-	  if (typename_p)
+	  if (decl && typename_p)
 	    USING_DECL_TYPENAME_P (decl) = 1;
 
 	  if (check_for_bare_parameter_packs (decl))
             return false;
-          else
+	  else
 	    /* Add it to the list of members in this class.  */
 	    finish_member_declaration (decl);
 	}
Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c	(revision 182410)
+++ gcc/cp/name-lookup.c	(working copy)
@@ -3189,6 +3189,7 @@ do_class_using_decl (tree scope, tree na
   tree binfo;
   tree base_binfo;
   int i;
+  base_kind b_kind;
 
   if (name == error_mark_node)
     return NULL_TREE;
@@ -3242,35 +3243,30 @@ do_class_using_decl (tree scope, tree na
 
      In general, we cannot check this constraint in a template because
      we do not know the entire set of base classes of the current
-     class type.  However, if all of the base classes are
-     non-dependent, then we can avoid delaying the check until
-     instantiation.  */
-  if (!scope_dependent_p)
-    {
-      base_kind b_kind;
-      binfo = lookup_base (current_class_type, scope, ba_any, &b_kind);
-      if (b_kind < bk_proper_base)
+     class type.  */
+
+  binfo = lookup_base (current_class_type, scope, ba_any, &b_kind);
+  if (b_kind < bk_proper_base)
+    {
+      if (!bases_dependent_p)
 	{
-	  if (!bases_dependent_p)
-	    {
-	      error_not_base_type (scope, current_class_type);
-	      return NULL_TREE;
-	    }
+	  error_not_base_type (scope, current_class_type);
+	  return NULL_TREE;
 	}
-      else if (!name_dependent_p)
+    }
+  else if (!name_dependent_p)
+    {
+      decl = lookup_member (binfo, name, 0, false, tf_warning_or_error);
+      if (!decl)
 	{
-	  decl = lookup_member (binfo, name, 0, false, tf_warning_or_error);
-	  if (!decl)
-	    {
-	      error ("no members matching %<%T::%D%> in %q#T", scope, name,
-		     scope);
-	      return NULL_TREE;
-	    }
-	  /* The binfo from which the functions came does not matter.  */
-	  if (BASELINK_P (decl))
-	    decl = BASELINK_FUNCTIONS (decl);
+	  error ("no members matching %<%T::%D%> in %q#T", scope, name,
+		 scope);
+	  return NULL_TREE;
 	}
-   }
+      /* The binfo from which the functions came does not matter.  */
+      if (BASELINK_P (decl))
+	decl = BASELINK_FUNCTIONS (decl);
+    }
 
   value = build_lang_decl (USING_DECL, name, NULL_TREE);
   USING_DECL_DECLS (value) = decl;
