C++ PATCH: PR 14821, 14833

Mark Mitchell mark@codesourcery.com
Mon May 24 03:24:00 GMT 2004


This patch fixes two more C++ regressions, both very straightforward.
PR14821 is a significant issue in that it prevented redefinition of
namespace aliases, which, as noted in the report, is an import feature
in some libraries.

Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.

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

2004-05-23  Mark Mitchell  <mark@codesourcery.com>

	PR c++/14821
	* name-lookup.c (supplement_binding): Allow redefinitions of
	namespace aliases.

	PR c++/14883
	* parser.c (cp_parser_template_argument): Robustify.

2004-05-23  Mark Mitchell  <mark@codesourcery.com>

	PR c++/14821
	* g++.dg/other/ns1.C: New test.

	PR c++/14883
	* g++.dg/template/invalid1.C: New test.

Index: cp/name-lookup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.34.2.11
diff -c -5 -p -r1.34.2.11 name-lookup.c
*** cp/name-lookup.c	1 Apr 2004 20:03:06 -0000	1.34.2.11
--- cp/name-lookup.c	23 May 2004 17:50:36 -0000
*************** supplement_binding (cxx_binding *binding
*** 495,509 ****
  	   && !DECL_CLASS_SCOPE_P (decl))
      {
        duplicate_decls (decl, binding->value);
        ok = false;
      }
    else
      {
        error ("declaration of `%#D'", decl);
!       cp_error_at ("conflicts with previous declaration `%#D'",
! 		   binding->value);
        ok = false;
      }
  
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ok);
  }
--- 495,520 ----
  	   && !DECL_CLASS_SCOPE_P (decl))
      {
        duplicate_decls (decl, binding->value);
        ok = false;
      }
+   else if (TREE_CODE (decl) == NAMESPACE_DECL
+ 	   && TREE_CODE (bval) == NAMESPACE_DECL
+ 	   && DECL_NAMESPACE_ALIAS (decl)
+ 	   && DECL_NAMESPACE_ALIAS (bval)
+ 	   && ORIGINAL_NAMESPACE (bval) == ORIGINAL_NAMESPACE (decl))
+     /* [namespace.alias]
+        
+       In a declarative region, a namespace-alias-definition can be
+       used to redefine a namespace-alias declared in that declarative
+       region to refer only to the namespace to which it already
+       refers.  */
+     ok = false;
    else
      {
        error ("declaration of `%#D'", decl);
!       cp_error_at ("conflicts with previous declaration `%#D'", bval);
        ok = false;
      }
  
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ok);
  }
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.157.2.26
diff -c -5 -p -r1.157.2.26 parser.c
*** cp/parser.c	23 Apr 2004 13:00:11 -0000	1.157.2.26
--- cp/parser.c	23 May 2004 17:50:37 -0000
*************** cp_parser_template_argument (cp_parser* 
*** 8326,8341 ****
       really finished.  */
    if (!cp_parser_next_token_ends_template_argument_p (parser))
      cp_parser_error (parser, "expected template-argument");
    if (!cp_parser_error_occurred (parser))
      {
!       /* Figure out what is being referred to.  */
!       argument = cp_parser_lookup_name (parser, argument,
! 					/*is_type=*/false,
! 					/*is_template=*/template_p,
! 					/*is_namespace=*/false,
! 					/*check_dependency=*/true);
        if (TREE_CODE (argument) != TEMPLATE_DECL
  	  && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
  	cp_parser_error (parser, "expected template-name");
      }
    if (cp_parser_parse_definitely (parser))
--- 8326,8345 ----
       really finished.  */
    if (!cp_parser_next_token_ends_template_argument_p (parser))
      cp_parser_error (parser, "expected template-argument");
    if (!cp_parser_error_occurred (parser))
      {
!       /* Figure out what is being referred to.  If the id-expression
! 	 was for a class template specialization, then we will have a
! 	 TYPE_DECL at this point.  There is no need to do name lookup
! 	 at this point in that case.  */
!       if (TREE_CODE (argument) != TYPE_DECL)
! 	argument = cp_parser_lookup_name (parser, argument,
! 					  /*is_type=*/false,
! 					  /*is_template=*/template_p,
! 					  /*is_namespace=*/false,
! 					  /*check_dependency=*/true);
        if (TREE_CODE (argument) != TEMPLATE_DECL
  	  && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
  	cp_parser_error (parser, "expected template-name");
      }
    if (cp_parser_parse_definitely (parser))
Index: testsuite/g++.dg/other/ns1.C
===================================================================
RCS file: testsuite/g++.dg/other/ns1.C
diff -N testsuite/g++.dg/other/ns1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/other/ns1.C	23 May 2004 17:43:43 -0000
***************
*** 0 ****
--- 1,13 ----
+ // PR c++/14821
+ 
+ namespace A {
+   namespace B {}
+ }
+ 
+ namespace A {
+   namespace Alias = ::A::B;
+ }
+ 
+ namespace A {
+   namespace Alias = ::A::B;
+ }
Index: testsuite/g++.dg/template/invalid1.C
===================================================================
RCS file: testsuite/g++.dg/template/invalid1.C
diff -N testsuite/g++.dg/template/invalid1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/invalid1.C	23 May 2004 17:43:43 -0000
***************
*** 0 ****
--- 1,7 ----
+ // PR c++/14883
+ 
+ template < class T > struct DomainTraits {};
+ template < int Dim > class Interval;
+ template < class DT > class Domain {};
+ template <> class Interval < 1 >:public Domain < DomainTraits < Interval < 1 >
+ >> {}; // { dg-error "" }



More information about the Gcc-patches mailing list