Bug 47 - nested classes broken
Summary: nested classes broken
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0
: P3 normal
Target Milestone: ---
Assignee: Jeffrey D. Oldham
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2000-03-05 02:16 UTC by martin
Modified: 2003-07-25 17:33 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2002-12-31 00:00:00


Attachments
nested.21Jan.10.2.patch (1.83 KB, application/octet-stream)
2003-05-21 15:16 UTC, martin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description martin 2000-03-05 02:16:02 UTC
 Date: Sun, 26 Sep 1999 22:47:46 -0700
 Original-Message-Id: <199909270547.WAA32443@linux1.magma-da.com>


 Dear gcc maintainers,

 In gcc-2.95.1 the scoping of nested classes is broken.   The snippet below
 compiles with gcc-2.7.2, egcs-1.1.2 and a wide variety of newer commercial
 C++ compilers, but it fails on 2.95.1.

 Thanks,
 -Raymond


 ----------------------------------------------------------------------
 49[linux1:]~/src/test>cat namescope.cxx
 class A {
 public:
  class B;
  class C;
 };

 class A::B {
 };

 class A::C {
  class D;
 };

 class A::C::D {
 public:
  B* foo();         // A::B should be in scope
 };
 ----------------------------------------------------------------------

 50[linux1:]~/src/test>/usr/local/gcc-2.95/bin/g++ -v  namescope.cxx
 Reading specs from /usr/local/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/specs
 gcc version 2.95.1 19990816 (release)
  /usr/local/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ namescope.cxx /tmp/cc8RbNC5.ii
 GNU CPP version 2.95.1 19990816 (release) (i386 Linux/ELF)
 #include "..." search starts here:
 #include <...> search starts here:
  /usr/local/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/../../../../include/g++-3
  /usr/local/include
  /usr/local/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/../../../../i686-pc-linux-gnu/include
  /usr/local/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/include
  /usr/include
 End of search list.
 The following default directories have been omitted from the search path:
 End of omitted list.
  /usr/local/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/cc1plus /tmp/cc8RbNC5.ii -quiet -dumpbase namescope.cc -version -o /tmp/ccbQ8vF6.s
 GNU C++ version 2.95.1 19990816 (release) (i686-pc-linux-gnu) compiled by GNU C version 2.95.1 19990816 (release).
 namescope.cxx:16: syntax error before `*'

 51[linux1:]~/src/test>
 ----------------------------------------------------------------------
 FYI:

 51[linux1:]~/src/test>g++ -v -Wall -c namescope.cxx
 Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
 gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
  /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -Wall -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ namescope.cxx /tmp/ccibKqii.ii
 GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF)
 #include "..." search starts here:
 #include <...> search starts here:
  /usr/include/g++-2
  /usr/local/include
  /usr/i386-redhat-linux/include
  /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include
  /usr/include
 End of search list.
  /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1plus /tmp/ccibKqii.ii -quiet -dumpbase namescope.cc -Wall -version -o /tmp/ccJ9v2Sl.s
 GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
  as -V -Qy -o namescope.o /tmp/ccJ9v2Sl.s
 GNU assembler version 2.9.1 (i386-redhat-linux), using BFD version 2.9.1.0.23
 52[linux1:]~/src/test>
 ----------------------------------------------------------------------

Release:
2.95.2 3.0
Comment 1 martin 2000-03-05 02:16:02 UTC
Fix:
The regression for the given source code was that the parsing of the return value 'B' inside A::C::D failed. The lexing code was incorrectly oversimplified so, when searching for a declaration of 'B' inside D, a declaration was not found. Thus, 'B' was incorrectly lexed as IDENTIFIER, not TYPENAME. Thus, the parsing became confused. The patch resurrects code to ensure that a declaration for 'B' is searched when dealing with nested code.

This problem does not occur with the parser in 3.4.

Jeffrey D. Oldham
oldham@codesourcery.com
Comment 2 Martin v. Loewis 2000-03-08 23:31:14 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed as a bug
Comment 3 Martin v. Loewis 2000-03-09 07:31:14 UTC
From: loewis@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org, martin@loewis.home.cs.tu-berlin.de,
  nobody@gcc.gnu.org, raymond@magma.magma-da.com
Cc:  
Subject: Re: c++/47
Date: 9 Mar 2000 07:31:14 -0000

 Old Synopsis: [not accepted] nested classes broken
 New Synopsis: nested classes broken
 
 State-Changed-From-To: open->analyzed
 State-Changed-By: loewis
 State-Changed-When: Wed Mar  8 23:31:14 2000
 State-Changed-Why:
     Confirmed as a bug  
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=47&database=gcc
Comment 4 Nathan Sidwell 2001-11-21 01:50:24 UTC
State-Changed-From-To: analyzed->suspended
State-Changed-Why: this is fixed on the cp-parser branch, and so suspended
    until that is folded onto the mainline
Comment 5 Nathan Sidwell 2001-11-21 09:50:24 UTC
From: nathan@gcc.gnu.org
To: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org,
  martin@loewis.home.cs.tu-berlin.de, nobody@gcc.gnu.org,
  raymond@magma.magma-da.com
Cc:  
Subject: Re: c++/47: nested classes broken
Date: 21 Nov 2001 09:50:24 -0000

 Synopsis: nested classes broken
 
 State-Changed-From-To: analyzed->suspended
 State-Changed-By: nathan
 State-Changed-When: Wed Nov 21 01:50:24 2001
 State-Changed-Why:
     this is fixed on the cp-parser branch, and so suspended
     until that is folded onto the mainline
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=47&database=gcc
Comment 6 Nathanael C. Nerode 2002-12-30 07:26:57 UTC
State-Changed-From-To: suspended->analyzed
State-Changed-Why: Confirmed still present in mainline (3.4) as of 2002-12-30, after new C++ parser merged in.
Comment 7 Jeffrey D. Oldham 2003-01-21 19:00:30 UTC
From: oldham@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/47
Date: 21 Jan 2003 19:00:30 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	oldham@gcc.gnu.org	2003-01-21 19:00:30
 
 Modified files:
 	gcc/cp         : ChangeLog cp-tree.h decl.c search.c 
 
 Log message:
 	2003-01-21  Jeffrey D. Oldham  <oldham@codesourcery.com>
 	
 	PR c++/47
 	* cp-tree.h (lookup_nested_field): Add declaration.
 	* decl.c (lookup_name_real): Call lookup_nested_field.
 	* search.c (lookup_nested_field): Add function.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.57&r2=1.2685.2.114.2.58
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.681.2.12.2.10&r2=1.681.2.12.2.11
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.866.2.36.2.14&r2=1.866.2.36.2.15
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.223.2.3.4.1&r2=1.223.2.3.4.2
 
Comment 8 Jeffrey D. Oldham 2003-01-22 17:45:53 UTC
Responsible-Changed-From-To: unassigned->oldham
Responsible-Changed-Why: Fixer.
Comment 9 Jeffrey D. Oldham 2003-01-22 17:45:53 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed.
Comment 10 Jeffrey D. Oldham 2003-01-28 03:21:09 UTC
From: oldham@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/47
Date: 28 Jan 2003 03:21:09 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	oldham@gcc.gnu.org	2003-01-28 03:21:09
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.old-deja/g++.other: lookup24.C 
 
 Log message:
 	2003-01-27  Jeffrey D. Oldham  <oldham@codesourcery.com>
 	
 	PR c++/47
 	* g++.old-deja/g++.other/lookup24.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.84&r2=1.1672.2.166.2.85
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.other/lookup24.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 

Comment 11 Jeffrey D. Oldham 2003-01-28 03:22:27 UTC
From: oldham@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/47
Date: 28 Jan 2003 03:22:27 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	oldham@gcc.gnu.org	2003-01-28 03:22:27
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.old-deja/g++.other: lookup24.C 
 
 Log message:
 	2003-01-27  Jeffrey D. Oldham  <oldham@codesourcery.com>
 	
 	PR c++/47
 	* g++.old-deja/g++.other/lookup24.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.27&r2=1.2261.2.28
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.other/lookup24.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.4.1
 

Comment 12 Jeffrey D. Oldham 2003-01-28 03:24:45 UTC
From: oldham@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/47
Date: 28 Jan 2003 03:24:45 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	oldham@gcc.gnu.org	2003-01-28 03:24:45
 
 Modified files:
 	gcc/cp         : ChangeLog cp-tree.h decl.c search.c 
 
 Log message:
 	2003-01-27  Jeffrey D. Oldham  <oldham@codesourcery.com>
 	
 	PR c++/47
 	* cp-tree.h (lookup_nested_field): Add declaration.
 	* decl.c (lookup_name_real): Call lookup_nested_field.
 	* search.c (lookup_nested_field): Add function.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.24&r2=1.3076.2.25
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.776.2.4&r2=1.776.2.5
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.6&r2=1.965.2.7
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.243&r2=1.243.2.1
 

Comment 13 Jeffrey D. Oldham 2003-01-28 03:26:00 UTC
From: oldham@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/47
Date: 28 Jan 2003 03:26:00 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	oldham@gcc.gnu.org	2003-01-28 03:26:00
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.old-deja/g++.other: lookup24.C 
 
 Log message:
 	2003-01-27  Jeffrey D. Oldham  <oldham@codesourcery.com>
 	
 	PR c++/47
 	* g++.old-deja/g++.other/lookup24.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2373&r2=1.2374
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.other/lookup24.C.diff?cvsroot=gcc&r1=1.1&r2=1.2