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]

(C++) patch to diagnose misplaced specialization


Fixes g++.pt/explicit37.C.

1999-02-07  Jason Merrill  <jason@yorick.cygnus.com>

	* pt.c (maybe_process_partial_specialization): Complain about
	specialization in wrong namespace.
	* tree.c (decl_namespace_context): New fn.

Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.257
diff -c -p -r1.257 pt.c
*** pt.c	1999/02/05 02:42:45	1.257
--- pt.c	1999/02/07 23:41:30
*************** maybe_process_partial_specialization (ty
*** 672,677 ****
--- 672,684 ----
        if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
  	  && TYPE_SIZE (type) == NULL_TREE)
  	{
+ 	  if (current_namespace
+ 	      != decl_namespace_context (CLASSTYPE_TI_TEMPLATE (type)))
+ 	    {
+ 	      cp_pedwarn ("specializing `%#T' in different namespace", type);
+ 	      cp_pedwarn_at ("  from definition of `%#D'",
+ 			    CLASSTYPE_TI_TEMPLATE (type));
+ 	    }
  	  SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (type);
  	  if (processing_template_decl)
  	    push_template_decl (TYPE_MAIN_DECL (type));
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.94
diff -c -p -r1.94 tree.c
*** tree.c	1999/01/26 02:33:46	1.94
--- tree.c	1999/02/07 23:41:31
*************** hack_decl_function_context (decl)
*** 2384,2389 ****
--- 2384,2407 ----
    return decl_function_context (decl);
  }
  
+ /* Returns the namespace that contains DECL, whether directly or
+    indirectly.  */
+ 
+ tree
+ decl_namespace_context (decl)
+      tree decl;
+ {
+   while (1)
+     {
+       if (TREE_CODE (decl) == NAMESPACE_DECL)
+ 	return decl;
+       else if (TYPE_P (decl))
+ 	decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
+       else
+ 	decl = CP_DECL_CONTEXT (decl);
+     }
+ }
+ 
  /* Return truthvalue of whether T1 is the same tree structure as T2.
     Return 1 if they are the same.
     Return 0 if they are understandably different.
Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.194
diff -c -p -r1.194 cp-tree.h
*** cp-tree.h	1999/02/05 02:55:44	1.194
--- cp-tree.h	1999/02/07 23:41:31
*************** cp-tree.h		PROT
*** 3288,3293 ****
--- 3288,3294 ----
  extern tree get_type_decl			PROTO((tree));
  extern tree vec_binfo_member			PROTO((tree, tree));
  extern tree hack_decl_function_context 		PROTO((tree));
+ extern tree decl_namespace_context 		PROTO((tree));
  extern tree lvalue_type				PROTO((tree));
  extern tree error_type				PROTO((tree));
  extern tree make_temp_vec			PROTO((int));


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