This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 21369


This patch fixes PR c++/21369.  

We were treating:

  template <typename T>
  struct S * ...

as a declaration of a template class "S".

Tested on x86-64-unknown-linux-gnu, applied on the mainline and on the
4.0 branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-10-11  Mark Mitchell  <mark@codesourcery.com>

	PR c++/21369
	* parser.c (cp_parser_elaborated_type_specifier): Don't treat
	class types as templates if the type is not appearing as part of a
	type definition or declaration.

2005-10-11  Mark Mitchell  <mark@codesourcery.com>

	PR c++/21369
	* g++.dg/parse/ret-type3.C: New test.

Index: gcc/cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.362
diff -c -5 -p -r1.362 parser.c
*** gcc/cp/parser.c	10 Oct 2005 22:30:16 -0000	1.362
--- gcc/cp/parser.c	11 Oct 2005 14:55:22 -0000
*************** cp_parser_elaborated_type_specifier (cp_
*** 10064,10073 ****
--- 10064,10075 ----
  	     Also, `new struct S' or `sizeof (struct S)' never results in the
  	     definition of a new type; a new type can only be declared in a
  	     declaration context.  */
  
  	  tag_scope ts;
+ 	  bool template_p;
+ 
  	  if (is_friend)
  	    /* Friends have special name lookup rules.  */
  	    ts = ts_within_enclosing_non_class;
  	  else if (is_declaration
  		   && cp_lexer_next_token_is (parser->lexer,
*************** cp_parser_elaborated_type_specifier (cp_
*** 10080,10091 ****
  	  /* Warn about attributes. They are ignored.  */
  	  if (attributes)
  	    warning (OPT_Wattributes,
  		     "type attributes are honored only at type definition");
  
! 	  type = xref_tag (tag_type, identifier, ts,
! 			   parser->num_template_parameter_lists);
  	}
      }
    if (tag_type != enum_type)
      cp_parser_check_class_key (tag_type, type);
  
--- 10082,10096 ----
  	  /* Warn about attributes. They are ignored.  */
  	  if (attributes)
  	    warning (OPT_Wattributes,
  		     "type attributes are honored only at type definition");
  
! 	  template_p = 
! 	    (parser->num_template_parameter_lists
! 	     && (cp_parser_next_token_starts_class_definition_p (parser)
! 		 || cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)));
! 	  type = xref_tag (tag_type, identifier, ts, template_p);
  	}
      }
    if (tag_type != enum_type)
      cp_parser_check_class_key (tag_type, type);
  
Index: gcc/testsuite/g++.dg/parse/ret-type3.C
===================================================================
RCS file: gcc/testsuite/g++.dg/parse/ret-type3.C
diff -N gcc/testsuite/g++.dg/parse/ret-type3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/g++.dg/parse/ret-type3.C	11 Oct 2005 14:55:24 -0000
***************
*** 0 ****
--- 1,8 ----
+ // PR c++/21369
+ 
+ struct bar;
+ 
+ template <class T> struct bar *foo (T *p)
+ {
+   return p->t;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]