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] Fix bug 2526


Hi,
I've installed the attached on the mainline only.

It fixes bug 2526. We ICE'd trying to pop a
now hidden inherited typedef. When non-pedantic a template type's
dependant bases are injected into the scope, and this sort of friendliness
overrides that.

built & tested on i686-pc-linux-gnu, approved by Mark.

nathan

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-05-18  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/2526
	* decl.c (pushdecl): Adjust error string.
	(xref_tag): Adjust friend class injection warning. Remove the
	inherited name from the class shadowed scope.

2001-05-18  Nathan Sidwell  <nathan@codesourcery.com>

	* g++.old-deja/g++.pt/inherit2.C: Remove XFAIL.
	* g++.old-deja/g++.pt/crash67.C: New test.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.782
diff -c -3 -p -r1.782 decl.c
*** decl.c	2001/05/04 06:28:52	1.782
--- decl.c	2001/05/08 15:47:15
*************** pushdecl (x)
*** 3938,3944 ****
  	  else if (t == wchar_decl_node)
  	    {
  	      if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
! 		cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x));
  
  	      /* Throw away the redeclaration.  */
  	      return t;
--- 3938,3945 ----
  	  else if (t == wchar_decl_node)
  	    {
  	      if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
! 		cp_pedwarn ("redeclaration of `wchar_t' as `%T'",
! 			    TREE_TYPE (x));
  
  	      /* Throw away the redeclaration.  */
  	      return t;
*************** xref_tag (code_type_node, name, globaliz
*** 12543,12558 ****
    if (t && globalize && TREE_CODE (t) == TYPENAME_TYPE)
      {
        static int explained;
  
!       cp_warning ("`%s %T' declares a new type at namespace scope;\n\
! to refer to the inherited type, say `%s %T::%T'%s",
! 		  tag_name (tag_code), name, tag_name (tag_code),
! 		  constructor_name (current_class_type), TYPE_IDENTIFIER (t),
! 		  (!explained ? "\n\
! (names from dependent base classes are not visible to unqualified name lookup)"
! 		   : ""));
! 
!       explained = 1;
      }
  
    if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM
--- 12544,12569 ----
    if (t && globalize && TREE_CODE (t) == TYPENAME_TYPE)
      {
        static int explained;
+       tree shadowed;
  
!       cp_warning ("`%s %T' declares a new type at namespace scope",
! 		  tag_name (tag_code), name);
!       if (!explained++)
! 	cp_warning ("  names from dependent base classes are not visible to unqualified name lookup - to refer to the inherited type, say `%s %T::%T'%s",
! 		    tag_name (tag_code),
! 		    constructor_name (current_class_type),
! 		    TYPE_IDENTIFIER (t));
! 
!       /* We need to remove the class scope binding for the
!          TYPENAME_TYPE as otherwise poplevel_class gets confused. */
!       for (shadowed = b->class_shadowed;
! 	   shadowed;
! 	   shadowed = TREE_CHAIN (shadowed))
! 	if (TREE_TYPE (shadowed) == TYPE_NAME (t))
! 	  {
! 	    TREE_PURPOSE (shadowed) = NULL_TREE;
! 	    break;
! 	  }
      }
  
    if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM
Index: testsuite/g++.old-deja/g++.pt/inherit2.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.pt/inherit2.C,v
retrieving revision 1.2
diff -c -3 -p -r1.2 inherit2.C
*** inherit2.C	2001/02/12 04:10:07	1.2
--- inherit2.C	2001/05/08 15:47:19
***************
*** 1,7 ****
  // Test that we warn about unqualified references to implicit typenames.
! // Bug: g++ is confused by the binding for ::AN and crashes.
  // Special g++ Options:
! // excess errors test - XFAIL *-*-*
  
  template <class T> struct A {
    struct AA { };
--- 1,7 ----
  // Test that we warn about unqualified references to implicit typenames.
! 
  // Special g++ Options:
! // Build don't link:
  
  template <class T> struct A {
    struct AA { };
// Build don't link:
// Special g++ Options: 
// 
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 6 May 2001 <nathan@codesourcery.com>

// Bug 2526. We ICE'd after diagnosing dependant name confusion in
// friendliness when not being pedantic.

template<typename T>
struct B
{
  typedef B<T> Mother;
};

template<typename T>
struct D : B<T>
{
  friend class Mother; // WARNING - defines namespace class
};

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