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,committed] Fix PR11076 (ICE resolve typename too early)


Hi

The following patch fixes the ICE on invalid code reported as PR11076.
There are actually 2 problems here.

First, 'cp_parser_direct_declarator' resolves some typename in declarations
too early because it processes all declarations, including the ones
declared in class.  For example, in the testcase included in the patch
below, we have access declaration like

    X::Y;

where 'X' is a typename.  This should be treated as dependent name and
resolved during instantiation rather than parsing.  The patch changes
'cp_parser_direct_declarator' so that only typenames in namespace scope
declaration are processed as it is intended for.

Second, the diagnostic produced for invalid using declaration is wrong.
For code like

    struct A { using B::f; };

an error message

    type 'A' is not a base type for type 'B'

is generated rather than the other way around (type 'B' is not a base type
for type 'A').  This is simply a result of wrong arguments supplied to 
an 'error_not_base_type' call.

Tested on i686-pc-linux-gnu.  Applied to mainline as obvious.

--Kriang


2003-10-24  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/11076
	* class.c (handle_using_decl): Swap arguments of error_not_base_type.
	* parser.c (cp_parser_direct_declarator): Only resolve typename for
	namespace scope declarations.

2003-10-24  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/11076
	* g++.dg/template/crash13.C: New test.


diff -cprN gcc-main-save/gcc/cp/class.c gcc-main-new/gcc/cp/class.c
*** gcc-main-save/gcc/cp/class.c	Tue Oct 21 21:16:00 2003
--- gcc-main-new/gcc/cp/class.c	Thu Oct 23 18:40:22 2003
*************** handle_using_decl (tree using_decl, tree
*** 1107,1113 ****
    binfo = lookup_base (t, ctype, ba_any, NULL);
    if (! binfo)
      {
!       error_not_base_type (t, ctype);
        return;
      }
    
--- 1107,1113 ----
    binfo = lookup_base (t, ctype, ba_any, NULL);
    if (! binfo)
      {
!       error_not_base_type (ctype, t);
        return;
      }
    
diff -cprN gcc-main-save/gcc/cp/parser.c gcc-main-new/gcc/cp/parser.c
*** gcc-main-save/gcc/cp/parser.c	Tue Oct 21 21:16:00 2003
--- gcc-main-new/gcc/cp/parser.c	Thu Oct 23 18:36:17 2003
*************** cp_parser_direct_declarator (cp_parser* 
*** 9871,9877 ****
  	  if (declarator == error_mark_node)
  	    break;
  	  
! 	  if (TREE_CODE (declarator) == SCOPE_REF)
  	    {
  	      tree scope = TREE_OPERAND (declarator, 0);
  
--- 9871,9878 ----
  	  if (declarator == error_mark_node)
  	    break;
  	  
! 	  if (TREE_CODE (declarator) == SCOPE_REF
! 	      && !current_scope ())
  	    {
  	      tree scope = TREE_OPERAND (declarator, 0);
  
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/crash13.C gcc-main-new/gcc/testsuite/g++.dg/template/crash13.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/crash13.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/crash13.C	Fri Oct 24 19:52:16 2003
***************
*** 0 ****
--- 1,18 ----
+ // { dg-do compile }
+ 
+ // Origin: Volker Reichelt <reichelt@gcc.gnu.org>
+ 
+ // PR c++/11076: ICE for invalid access declaration containing typename.
+ 
+ template<typename, typename T=void> struct A
+ {
+     typedef A<T,T> B;
+ };
+ 
+ template <typename T> struct C
+ {				// { dg-error "not a base type" }
+     typedef typename A<T>::B X;
+     X::Y;
+ };
+ 
+ C<void> c;			// { dg-error "instantiated" }


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