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]

[mainline] PATCH for C++/11762


this is a (partial) fix for PR C++/11762.  Now, we do no longer ICE.
However, the disease is deeper:  We should be doing name lookup at
the point of declaration instead of counting on duplicate_decls to
sweep out the mess.  For example we're still ICEing on

    namespace N { }
    namespace M { }

    namespace N = M;

in duplicate_decls.  That function is supposed to do too many things.
It should be broken into logical units one day of the other. 

Bootstrapped and regtested on an i686-pc-linux-gnu.

-- Gaby

Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
retrieving revision 2.996
diff -p -r2.996 ChangeLog
*** ChangeLog	7 Sep 2003 11:59:41 -0000	2.996
--- ChangeLog	7 Sep 2003 18:44:56 -0000
***************
*** 1,3 ****
--- 1,10 ----
+ 2003-09-07  Gabriel Dos Reis  <gcc@integrable-solutions.net>
+ 
+ 	* c-pretty-print.h (pp_c_left_brace): Declare.
+ 	(pp_c_right_brace): Likewise.
+ 	* c-pretty-print.c (pp_c_left_brace): Now a function
+ 	(pp_c_right_brace): Likewise.
+ 
  2003-09-07  Gabriel Dos Reis  <gdr@integrable-solutions.net>
  
  	* diagnostic.c (warn_deprecated_use): Move to toplev.c
Index: c-pretty-print.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pretty-print.h,v
retrieving revision 1.12
diff -p -r1.12 c-pretty-print.h
*** c-pretty-print.h	25 Aug 2003 19:10:48 -0000	1.12
--- c-pretty-print.h	7 Sep 2003 18:44:56 -0000
*************** extern void pp_c_pretty_printer_init (c_
*** 157,162 ****
--- 157,164 ----
  void pp_c_whitespace (c_pretty_printer *);
  void pp_c_left_paren (c_pretty_printer *);
  void pp_c_right_paren (c_pretty_printer *);
+ void pp_c_left_brace (c_pretty_printer *);
+ void pp_c_right_brace (c_pretty_printer *);
  void pp_c_dot (c_pretty_printer *);
  void pp_c_ampersand (c_pretty_printer *);
  void pp_c_arrow (c_pretty_printer *);
Index: c-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pretty-print.c,v
retrieving revision 1.25
diff -p -r1.25 c-pretty-print.c
*** c-pretty-print.c	25 Aug 2003 19:10:47 -0000	1.25
--- c-pretty-print.c	7 Sep 2003 18:44:56 -0000
*************** Software Foundation, 59 Temple Place - S
*** 41,58 ****
         pp_c_whitespace (PP);                 \
     } while (0)
  
- #define pp_c_left_brace(PP)           \
-   do {                                \
-     pp_left_brace (PP);               \
-     pp_base (PP)->padding = pp_none;  \
-   } while (0)
- 
- #define pp_c_right_brace(PP)          \
-   do {                                \
-     pp_right_brace (PP);              \
-     pp_base (PP)->padding = pp_none;  \
-   } while (0)
- 
  #define pp_c_left_bracket(PP)         \
    do {                                \
      pp_left_bracket (PP);             \
--- 41,46 ----
*************** void
*** 112,117 ****
--- 100,119 ----
  pp_c_right_paren (c_pretty_printer *pp)
  {
    pp_right_paren (pp);
+   pp_base (pp)->padding = pp_none;
+ }
+ 
+ void
+ pp_c_left_brace (c_pretty_printer *pp)
+ {
+   pp_left_brace (pp);
+   pp_base (pp)->padding = pp_none;
+ }
+ 
+ void
+ pp_c_right_brace (c_pretty_printer *pp)
+ {
+   pp_right_brace (pp);
    pp_base (pp)->padding = pp_none;
  }
  
Index: testsuite/g++.dg/lookup/struct1.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/lookup/struct1.C,v
retrieving revision 1.2
diff -p -r1.2 struct1.C
*** testsuite/g++.dg/lookup/struct1.C	12 Apr 2002 10:59:33 -0000	1.2
--- testsuite/g++.dg/lookup/struct1.C	7 Sep 2003 18:44:57 -0000
***************
*** 3,12 ****
  
  struct A;
  typedef struct A B;		// { dg-error "previous declaration" }
! struct B;			// { dg-error "conflicting types" }
  
  typedef struct { int i; } C;	// { dg-error "previous declaration" }
! struct C;			// { dg-error "conflicting types" }
  
  struct D;
  typedef struct D D;
--- 3,12 ----
  
  struct A;
  typedef struct A B;		// { dg-error "previous declaration" }
! struct B;			// { dg-error "conflicting declaration" }
  
  typedef struct { int i; } C;	// { dg-error "previous declaration" }
! struct C;			// { dg-error "conflicting declaration" }
  
  struct D;
  typedef struct D D;
Index: cp/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.3656
diff -p -r1.3656 ChangeLog
*** cp/ChangeLog	7 Sep 2003 11:15:45 -0000	1.3656
--- cp/ChangeLog	7 Sep 2003 18:45:11 -0000
***************
*** 1,3 ****
--- 1,17 ----
+ 2003-09-07  Gabriel Dos Reis  <gcc@integrable-solutions.net>
+ 
+ 	PR c++/11762
+ 	* error.c (dump_decl): Handle namespace-alias-definition.
+ 	* decl.c (warn_extern_redeclared_static): There is no point in
+ 	checking changes in storage class specifier for a namespace
+ 	declaration. 
+ 	(duplicate_decls): Tidy diagnostic message.
+ 	* cxx-pretty-print.c (pp_cxx_left_brace): New macro.
+ 	(pp_cxx_right_brace): Likewise.
+ 	(pp_cxx_original_namespace_definition): New function.
+ 	(pp_cxx_namespace_alias_definition): Likewise.
+ 	(pp_cxx_declaration): Use them.  Handle NAMESPACE_DECLs.
+ 
  Sun Sep  7 13:15:14 CEST 2003  Jan Hubicka  <jh@suse.cz>
  
  	* decl2.c (maybe_emit_vtables, write_out_vars, finish_file):
Index: cp/cxx-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cxx-pretty-print.c,v
retrieving revision 1.5
diff -p -r1.5 cxx-pretty-print.c
*** cp/cxx-pretty-print.c	29 Aug 2003 07:00:32 -0000	1.5
--- cp/cxx-pretty-print.c	7 Sep 2003 18:45:11 -0000
*************** static void pp_cxx_template_parameter (c
*** 45,50 ****
--- 45,52 ----
  #define pp_cxx_whitespace(PP)  pp_c_whitespace (pp_c_base (PP))
  #define pp_cxx_left_paren(PP)  pp_c_left_paren (pp_c_base (PP))
  #define pp_cxx_right_paren(PP) pp_c_right_paren (pp_c_base (PP))
+ #define pp_cxx_left_brace(PP)  pp_c_left_brace (pp_c_base (PP))
+ #define pp_cxx_right_brace(PP) pp_c_right_brace (pp_c_base (PP))
  #define pp_cxx_dot(PP)         pp_c_dot (pp_c_base (PP))
  #define pp_cxx_arrow(PP)       pp_c_arrow (pp_c_base (PP))
  #define pp_cxx_semicolon(PP)   pp_c_semicolon (pp_c_base (PP))
*************** pp_cxx_statement (cxx_pretty_printer *pp
*** 1471,1476 ****
--- 1473,1517 ----
      }
  }
  
+ /* original-namespace-definition:
+       namespace identifier { namespace-body }
+ 
+   As an edge case, we also handle unnamed namespace definition here.  */
+ 
+ static void
+ pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
+ {
+   pp_cxx_identifier (pp, "namespace");
+   if (DECL_NAME (t) != anonymous_namespace_name)
+     pp_cxx_unqualified_id (pp, t);
+   pp_cxx_whitespace (pp);
+   pp_cxx_left_brace (pp);
+   /* We do not print the namespace-body.  */
+   pp_cxx_whitespace (pp);
+   pp_cxx_right_brace (pp);
+ }
+ 
+ /* namespace-alias:
+       identifier
+ 
+    namespace-alias-definition:
+       namespace identifier = qualified-namespace-specifier ;
+ 
+    qualified-namespace-specifier:
+       ::(opt) nested-name-specifier(opt) namespace-name   */
+ 
+ static void
+ pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
+ {
+   pp_cxx_identifier (pp, "namespace");
+   pp_cxx_unqualified_id (pp, t);
+   pp_cxx_whitespace (pp);
+   pp_equal (pp);
+   pp_cxx_whitespace (pp);
+   pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
+   pp_cxx_semicolon (pp);
+ }
+ 
  /* simple-declaration:
        decl-specifier-seq(opt) init-declarator-list(opt)  */
  static void
*************** pp_cxx_declaration (cxx_pretty_printer *
*** 1618,1626 ****
  {
    if (!DECL_LANG_SPECIFIC (t))
      pp_cxx_simple_declaration (pp, t);
!   else if (DECL_USE_TEMPLATE (t) > 1)
      switch (DECL_USE_TEMPLATE (t))
        {
        case 2:
          pp_cxx_explicit_specialization (pp, t);
          break;
--- 1659,1671 ----
  {
    if (!DECL_LANG_SPECIFIC (t))
      pp_cxx_simple_declaration (pp, t);
!   else if (DECL_USE_TEMPLATE (t))
      switch (DECL_USE_TEMPLATE (t))
        {
+       case 1:
+         pp_cxx_template_declaration (pp, t);
+         break;
+         
        case 2:
          pp_cxx_explicit_specialization (pp, t);
          break;
*************** pp_cxx_declaration (cxx_pretty_printer *
*** 1632,1639 ****
        default:
          break;
        }
-   else if (DECL_TEMPLATE_INFO (t))
-     pp_cxx_template_declaration (pp, t);
    else switch (TREE_CODE (t))
      {
      case VAR_DECL:
--- 1677,1682 ----
*************** pp_cxx_declaration (cxx_pretty_printer *
*** 1646,1651 ****
--- 1689,1701 ----
          pp_cxx_function_definition (pp, t);
        else
          pp_cxx_simple_declaration (pp, t);
+       break;
+ 
+     case NAMESPACE_DECL:
+       if (DECL_NAMESPACE_ALIAS (t))
+         pp_cxx_namespace_alias_definition (pp, t);
+       else
+         pp_cxx_original_namespace_definition (pp, t);
        break;
  
      default:
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1123
diff -p -r1.1123 decl.c
*** cp/decl.c	6 Sep 2003 19:03:44 -0000	1.1123
--- cp/decl.c	7 Sep 2003 18:45:19 -0000
*************** warn_extern_redeclared_static (tree newd
*** 2736,2742 ****
  
    if (TREE_CODE (newdecl) == TYPE_DECL
        || TREE_CODE (newdecl) == TEMPLATE_DECL
!       || TREE_CODE (newdecl) == CONST_DECL)
      return;
  
    /* Don't get confused by static member functions; that's a different
--- 2736,2743 ----
  
    if (TREE_CODE (newdecl) == TYPE_DECL
        || TREE_CODE (newdecl) == TEMPLATE_DECL
!       || TREE_CODE (newdecl) == CONST_DECL
!       || TREE_CODE (newdecl) == NAMESPACE_DECL)
      return;
  
    /* Don't get confused by static member functions; that's a different
*************** duplicate_decls (tree newdecl, tree oldd
*** 3004,3011 ****
        else if (current_class_type == NULL_TREE
  	  || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
  	{
! 	  error ("conflicting types for `%#D'", newdecl);
! 	  cp_error_at ("previous declaration as `%#D'", olddecl);
  	}
      }
    else if (TREE_CODE (newdecl) == FUNCTION_DECL
--- 3005,3014 ----
        else if (current_class_type == NULL_TREE
  	  || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
  	{
! 	  error ("conflicting declaration '%#D'", newdecl);
! 	  cp_error_at ("'%D' has a previous declaration as `%#D'",
!                        olddecl, olddecl);
!           return false;
  	}
      }
    else if (TREE_CODE (newdecl) == FUNCTION_DECL
Index: cp/error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.234
diff -p -r1.234 error.c
*** cp/error.c	1 Sep 2003 05:02:11 -0000	1.234
--- cp/error.c	7 Sep 2003 18:45:19 -0000
*************** dump_decl (tree t, int flags)
*** 831,841 ****
        break;
  
      case NAMESPACE_DECL:
!       dump_scope (CP_DECL_CONTEXT (t), flags);
!       if (DECL_NAME (t) == anonymous_namespace_name)
! 	pp_identifier (cxx_pp, "<unnamed>");
        else
! 	pp_tree_identifier (cxx_pp, DECL_NAME (t));
        break;
  
      case SCOPE_REF:
--- 831,846 ----
        break;
  
      case NAMESPACE_DECL:
!       if (flags & TFF_DECL_SPECIFIERS)
!         pp_cxx_declaration (cxx_pp, t);
        else
!         {
!           dump_scope (CP_DECL_CONTEXT (t), flags);
!           if (DECL_NAME (t) == anonymous_namespace_name)
!             pp_identifier (cxx_pp, "<unnamed>");
!           else
!             pp_tree_identifier (cxx_pp, DECL_NAME (t));
!         }
        break;
  
      case SCOPE_REF:


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