Blame SOURCES/gcc32-c++-pr10558.patch

4ac4fd
2003-07-10  Mark Mitchell  <mark@codesourcery.com>
4ac4fd
4ac4fd
	PR c++/10558
4ac4fd
	* parse.y (class_template_ok_as_expr): New variable.
4ac4fd
	(template_arg_1): New non-terminal.
4ac4fd
	(primary): Issue errors about uses of class templates as
4ac4fd
	expressions.
4ac4fd
4ac4fd
	* g++.dg/parse/template8.C: New test.
4ac4fd
4ac4fd
--- gcc/cp/parse.y	10 Jul 2003 12:43:11 -0000	1.284.2.7
4ac4fd
+++ gcc/cp/parse.y	11 Jul 2003 08:39:55 -0000	1.284.2.8
4ac4fd
@@ -53,6 +53,8 @@ extern struct obstack permanent_obstack;
4ac4fd
 /* Like YYERROR but do call yyerror.  */
4ac4fd
 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
4ac4fd
 
4ac4fd
+static int class_template_ok_as_expr;
4ac4fd
+
4ac4fd
 #define OP0(NODE) (TREE_OPERAND (NODE, 0))
4ac4fd
 #define OP1(NODE) (TREE_OPERAND (NODE, 1))
4ac4fd
 
4ac4fd
@@ -422,7 +424,7 @@ cp_parse_init ()
4ac4fd
 %type   template_close_bracket
4ac4fd
 %type <ttype> apparent_template_type
4ac4fd
 %type <ttype> template_type template_arg_list template_arg_list_opt
4ac4fd
-%type <ttype> template_arg
4ac4fd
+%type <ttype> template_arg template_arg_1
4ac4fd
 %type <ttype> condition xcond paren_cond_or_null
4ac4fd
 %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
4ac4fd
 %type <ttype> complete_type_name notype_identifier nonnested_type
4ac4fd
@@ -1108,7 +1110,7 @@ template_close_bracket:
4ac4fd
 template_arg_list_opt:
4ac4fd
          /* empty */
4ac4fd
                  { $$ = NULL_TREE; }
4ac4fd
-       | template_arg_list
4ac4fd
+       | template_arg_list 
4ac4fd
        ;
4ac4fd
 
4ac4fd
 template_arg_list:
4ac4fd
@@ -1119,6 +1121,15 @@ template_arg_list:
4ac4fd
 	;
4ac4fd
 
4ac4fd
 template_arg:
4ac4fd
+		{ ++class_template_ok_as_expr; }
4ac4fd
+	template_arg_1 
4ac4fd
+		{ 
4ac4fd
+		  --class_template_ok_as_expr; 
4ac4fd
+		  $$ = $2; 
4ac4fd
+		}
4ac4fd
+	;
4ac4fd
+
4ac4fd
+template_arg_1:
4ac4fd
 	  type_id
4ac4fd
 		{ $$ = groktypename ($1.t); }
4ac4fd
 	| PTYPENAME
4ac4fd
@@ -1695,7 +1706,14 @@ primary:
4ac4fd
 		    $$ = $2;
4ac4fd
 		}
4ac4fd
 	| overqualified_id  %prec HYPERUNARY
4ac4fd
-		{ $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
4ac4fd
+		{ $$ = build_offset_ref (OP0 ($$), OP1 ($$));
4ac4fd
+		  if (!class_template_ok_as_expr 
4ac4fd
+		      && DECL_CLASS_TEMPLATE_P ($$))
4ac4fd
+		    {
4ac4fd
+		      error ("invalid use of template `%D'", $$); 
4ac4fd
+		      $$ = error_mark_node;
4ac4fd
+		    }
4ac4fd
+		}
4ac4fd
 	| overqualified_id '(' nonnull_exprlist ')'
4ac4fd
                 { $$ = finish_qualified_call_expr ($1, $3); }
4ac4fd
 	| overqualified_id LEFT_RIGHT
4ac4fd
--- gcc/testsuite/g++.dg/parse/template8.C	2005-01-27 14:27:08.338732320 +0100
4ac4fd
+++ gcc/testsuite/g++.dg/parse/template8.C	2003-07-16 18:05:35.000000000 +0200
4ac4fd
@@ -0,0 +1,16 @@
4ac4fd
+namespace N
4ac4fd
+{
4ac4fd
+
4ac4fd
+template <typename> struct A
4ac4fd
+{
4ac4fd
+  template <typename T> A(A<T>);
4ac4fd
+};
4ac4fd
+
4ac4fd
+}
4ac4fd
+
4ac4fd
+void foo(N::A<int>);
4ac4fd
+
4ac4fd
+void bar()
4ac4fd
+{
4ac4fd
+  foo(N::A); // { dg-error "" }
4ac4fd
+}