diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0ae6496ba8a255d7e545f49eaa714833209dfdce..e163f2360edda9d0eea524d4ec16dfe1dc1e4ae6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2003-07-25  Nathan Sidwell  <nathan@codesourcery.com>
+
+	* cp-tree.h (enum tsubst_flags_t): Add tf_user.
+	* decl.c (make_typename_type): Pass it.
+	* pt.c (lookup_template_class): Use it.
+	(resolve_typename_type): Pass it.
+	* semantics.c (finish_template_type): Pass it.
+
 2003-07-25  Nathan Sidwell  <nathan@codesourcery.com>
 
 	PR c++/11617
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 994298a061ceed0bd18ecc5eb4016d996e6327ac..eb7933687c85839988204f6761d6d8baf8a2a263 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -3054,8 +3054,10 @@ typedef enum tsubst_flags_t {
   tf_ignore_bad_quals = 1 << 2, /* ignore bad cvr qualifiers */
   tf_keep_type_decl = 1 << 3,	/* retain typedef type decls
 				   (make_typename_type use) */
-  tf_ptrmem_ok = 1 << 4      /* pointers to member ok (internal
-				instantiate_type use) */
+  tf_ptrmem_ok = 1 << 4,        /* pointers to member ok (internal
+				   instantiate_type use) */
+  tf_user = 1 << 5		/* Found template must be a user template
+				   (lookup_template_class use) */
 } tsubst_flags_t;
 
 /* The kind of checking we can do looking in a class hierarchy.  */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index cec42f377700013c9f431c1407a76c9839ac744a..27cb784913ac871bc040eafea16cd24f24ebcf80 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5523,7 +5523,7 @@ make_typename_type (tree context, tree name, tsubst_flags_t complain)
 					TREE_OPERAND (fullname, 1),
 					NULL_TREE, context,
 					/*entering_scope=*/0,
-	                                tf_error | tf_warning);
+	                                tf_error | tf_warning | tf_user);
 	}
       else
 	{
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 24c07bbdb24da71b326d1c39e200a404533bd7dc..66703723178712220d222ece30d76bf20db60f63 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3957,8 +3957,11 @@ lookup_template_class (tree d1,
 {
   tree template = NULL_TREE, parmlist;
   tree t;
-
+  
   timevar_push (TV_NAME_LOOKUP);
+  my_friendly_assert ((!arglist || TREE_CODE (arglist) == TREE_LIST)
+		      == ((complain & tf_user) != 0), 20030724);
+  
   if (TREE_CODE (d1) == IDENTIFIER_NODE)
     {
       if (IDENTIFIER_VALUE (d1) 
@@ -4018,11 +4021,10 @@ lookup_template_class (tree d1,
     }
 
   if (TREE_CODE (template) != TEMPLATE_DECL
-         /* If we're called from the parser, make sure it's a user visible
-            template.  */
-      || ((!arglist || TREE_CODE (arglist) == TREE_LIST)
-          && !DECL_TEMPLATE_PARM_P (template)
-          && !PRIMARY_TEMPLATE_P (template)))
+         /* Make sure it's a user visible template, if it was named by
+	    the user.  */
+      || ((complain & tf_user) && !DECL_TEMPLATE_PARM_P (template)
+	  && !PRIMARY_TEMPLATE_P (template)))
     {
       if (complain & tf_error)
         {
@@ -4033,6 +4035,8 @@ lookup_template_class (tree d1,
       POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
     }
 
+  complain &= ~tf_user;
+  
   if (DECL_TEMPLATE_TEMPLATE_PARM_P (template))
     {
       /* Create a new TEMPLATE_DECL and TEMPLATE_TEMPLATE_PARM node to store
@@ -11795,8 +11799,7 @@ resolve_typename_type (tree type, bool only_current_p)
       args = TREE_OPERAND (TYPENAME_TYPE_FULLNAME (type), 1);
       /* Instantiate the template.  */
       type = lookup_template_class (tmpl, args, NULL_TREE, NULL_TREE,
-				    /*entering_scope=*/0, 
-				    tf_error);
+				    /*entering_scope=*/0, tf_error | tf_user);
     }
   else
     type = error_mark_node;
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 50c74780daf4be34ad9d63ebc0f2bfb333443a1c..da34da293336c57d53c49b016fd59275313ddb17 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2183,8 +2183,8 @@ finish_template_type (tree name, tree args, int entering_scope)
   tree decl;
 
   decl = lookup_template_class (name, args,
-				NULL_TREE, NULL_TREE,
-	                        entering_scope, /*complain=*/1);
+				NULL_TREE, NULL_TREE, entering_scope,
+				tf_error | tf_warning | tf_user);
   if (decl != error_mark_node)
     decl = TYPE_STUB_DECL (decl);