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 for 3.4/4.0] Fix PR14479, 19487 (reject valid anonymousenum)


Hi

This patch fixes PR14479, 19487 regression on 3.4 and mainline.
We check if there are too many template header in
maybe_check_template_type which is called deep inside xref_tag.
Thus it may be used only during parsing but also some case
of template instantiation which is wrong.  One such case is
when tsubst'ing anonymous enum in class templates.

In the new parser, we already have cp_parser_check_template_parameters
that do the same thing.  So the function maybe_check_template_type,
only used in one place in the front-end, is considered redundant
and can be removed completely.

Tested on i686-pc-linux, OK for 3.4 branch and mainline?

--Kriang
***** PATCH FOR MAINLINE *****

2004-01-21  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/14479
	PR c++/19487
	* pt.c (maybe_check_template_type): Remove.
	* cp-tree.h (maybe_check_template_type): Remove prototype.
	* name-lookup.c (maybe_process_template_type_declaration): Don't
	use maybe_check_template_type.

2004-01-21  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/14479
	PR c++/19487
	* g++.dg/template/enum5.C: New test.


diff -cprN gcc-main-save/gcc/cp/cp-tree.h gcc-main-new/gcc/cp/cp-tree.h
*** gcc-main-save/gcc/cp/cp-tree.h	Wed Jan 12 18:00:25 2005
--- gcc-main-new/gcc/cp/cp-tree.h	Thu Jan 20 22:06:47 2005
*************** extern int is_specialization_of         
*** 4027,4033 ****
  extern bool is_specialization_of_friend         (tree, tree);
  extern int comp_template_args                   (tree, tree);
  extern void maybe_process_partial_specialization (tree);
- extern void maybe_check_template_type           (tree);
  extern tree most_specialized_instantiation      (tree);
  extern void print_candidates                    (tree);
  extern void instantiate_pending_templates       (int);
--- 4027,4032 ----
diff -cprN gcc-main-save/gcc/cp/name-lookup.c gcc-main-new/gcc/cp/name-lookup.c
*** gcc-main-save/gcc/cp/name-lookup.c	Thu Jan  6 22:16:17 2005
--- gcc-main-new/gcc/cp/name-lookup.c	Thu Jan 20 22:06:46 2005
*************** maybe_process_template_type_declaration 
*** 4520,4527 ****
      ;
    else
      {
-       maybe_check_template_type (type);
- 
        gcc_assert (IS_AGGR_TYPE (type) || TREE_CODE (type) == ENUMERAL_TYPE);
  
        if (processing_template_decl)
--- 4520,4525 ----
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c	Thu Jan 20 21:57:41 2005
--- gcc-main-new/gcc/cp/pt.c	Thu Jan 20 22:06:39 2005
*************** check_explicit_specialization (tree decl
*** 2101,2149 ****
    return decl;
  }
  
- /* TYPE is being declared.  Verify that the use of template headers
-    and such is reasonable.  Issue error messages if not.  */
- 
- void
- maybe_check_template_type (tree type)
- {
-   if (template_header_count)
-     {
-       /* We are in the scope of some `template <...>' header.  */
- 
-       int context_depth 
- 	= template_class_depth_real (TYPE_CONTEXT (type),
- 				     /*count_specializations=*/1);
- 
-       if (template_header_count <= context_depth)
- 	/* This is OK; the template headers are for the context.  We
- 	   are actually too lenient here; like
- 	   check_explicit_specialization we should consider the number
- 	   of template types included in the actual declaration.  For
- 	   example, 
- 
- 	     template <class T> struct S {
- 	       template <class U> template <class V>
- 	       struct I {};
- 	     }; 
- 
- 	   is invalid, but:
- 
- 	     template <class T> struct S {
- 	       template <class U> struct I;
- 	     }; 
- 
- 	     template <class T> template <class U.
- 	     struct S<T>::I {};
- 
- 	   is not.  */
- 	; 
-       else if (template_header_count > context_depth + 1)
- 	/* There are two many template parameter lists.  */
- 	error ("too many template parameter lists in declaration of %qT", type); 
-     }
- }
- 
  /* Returns 1 iff PARMS1 and PARMS2 are identical sets of template
     parameters.  These are represented in the same format used for
     DECL_TEMPLATE_PARMS.  */
--- 2101,2106 ----
***** PATCH FOR 3.4 BRANCH *****

2004-01-21  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/14479
	PR c++/19487
	* pt.c (maybe_check_template_type): Remove.
	* cp-tree.h (maybe_check_template_type): Remove prototype.
	* name-lookup.c (maybe_process_template_type_declaration): Don't
	use maybe_check_template_type.

2004-01-21  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/14479
	PR c++/19487
	* g++.dg/template/enum5.C: New test.


diff -cprN gcc-34-save/gcc/cp/cp-tree.h gcc-34-new/gcc/cp/cp-tree.h
*** gcc-34-save/gcc/cp/cp-tree.h	Tue Oct 12 22:57:59 2004
--- gcc-34-new/gcc/cp/cp-tree.h	Thu Jan 20 22:15:33 2005
*************** extern int is_specialization_of         
*** 3921,3927 ****
  extern bool is_specialization_of_friend         (tree, tree);
  extern int comp_template_args                   (tree, tree);
  extern void maybe_process_partial_specialization (tree);
- extern void maybe_check_template_type           (tree);
  extern tree most_specialized_instantiation      (tree);
  extern void print_candidates                    (tree);
  extern int instantiate_pending_templates        (void);
--- 3921,3926 ----
diff -cprN gcc-34-save/gcc/cp/name-lookup.c gcc-34-new/gcc/cp/name-lookup.c
*** gcc-34-save/gcc/cp/name-lookup.c	Wed Dec  8 17:36:45 2004
--- gcc-34-new/gcc/cp/name-lookup.c	Thu Jan 20 22:16:19 2005
*************** maybe_process_template_type_declaration 
*** 4542,4553 ****
      ;
    else
      {
-       maybe_check_template_type (type);
- 
        my_friendly_assert (IS_AGGR_TYPE (type)
  			  || TREE_CODE (type) == ENUMERAL_TYPE, 0);
  
- 
        if (processing_template_decl)
  	{
  	  /* This may change after the call to
--- 4542,4550 ----
diff -cprN gcc-34-save/gcc/cp/pt.c gcc-34-new/gcc/cp/pt.c
*** gcc-34-save/gcc/cp/pt.c	Fri Jan 21 22:47:56 2005
--- gcc-34-new/gcc/cp/pt.c	Thu Jan 20 22:16:53 2005
*************** check_explicit_specialization (tree decl
*** 1993,2041 ****
    return decl;
  }
  
- /* TYPE is being declared.  Verify that the use of template headers
-    and such is reasonable.  Issue error messages if not.  */
- 
- void
- maybe_check_template_type (tree type)
- {
-   if (template_header_count)
-     {
-       /* We are in the scope of some `template <...>' header.  */
- 
-       int context_depth 
- 	= template_class_depth_real (TYPE_CONTEXT (type),
- 				     /*count_specializations=*/1);
- 
-       if (template_header_count <= context_depth)
- 	/* This is OK; the template headers are for the context.  We
- 	   are actually too lenient here; like
- 	   check_explicit_specialization we should consider the number
- 	   of template types included in the actual declaration.  For
- 	   example, 
- 
- 	     template <class T> struct S {
- 	       template <class U> template <class V>
- 	       struct I {};
- 	     }; 
- 
- 	   is invalid, but:
- 
- 	     template <class T> struct S {
- 	       template <class U> struct I;
- 	     }; 
- 
- 	     template <class T> template <class U.
- 	     struct S<T>::I {};
- 
- 	   is not.  */
- 	; 
-       else if (template_header_count > context_depth + 1)
- 	/* There are two many template parameter lists.  */
- 	error ("too many template parameter lists in declaration of `%T'", type); 
-     }
- }
- 
  /* Returns 1 iff PARMS1 and PARMS2 are identical sets of template
     parameters.  These are represented in the same format used for
     DECL_TEMPLATE_PARMS.  */
--- 1993,1998 ----
diff -cprN gcc-34-save/gcc/testsuite/g++.dg/template/enum5.C gcc-34-new/gcc/testsuite/g++.dg/template/enum5.C
*** gcc-34-save/gcc/testsuite/g++.dg/template/enum5.C	Thu Jan  1 07:00:00 1970
--- gcc-34-new/gcc/testsuite/g++.dg/template/enum5.C	Tue Jan 18 23:13:46 2005
***************
*** 0 ****
--- 1,16 ----
+ // { dg-do compile }
+ 
+ // Origin: robertk@mathematik.uni-freiburg.de
+ //	   Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+ 
+ // PR c++/14479: Template header check for enum
+ 
+ template <int dim>
+ struct X {
+   enum { dimension = dim };
+   template<int d> void bar ();
+ };
+ 
+ template <>
+ template <>
+ void X<0>::bar<0> () {}

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