Bug 11972 - [3.4 regression] problem finding nested types in templates
Summary: [3.4 regression] problem finding nested types in templates
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P1 critical
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-08-18 21:13 UTC by poschmid
Modified: 2004-01-17 04:22 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-08-18 21:43:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description poschmid 2003-08-18 21:13:57 UTC
The code a.C is rejected by gcc 3.4. This breaks some parts of boost.

Environment:
System: Linux linux 2.4.20-4GB #1 Fri Jul 11 07:33:18 UTC 2003 i686 unknown unknown GNU/Linux
Architecture: i686
SuSE 8.2
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-threads=posix --enable-languages=c,c++,f77,objc --enable-__cxa_atexit --enable-debug

How-To-Repeat:
source code a.C
template<typename _Tp>
class allocator
{
    template<typename _Tp1>
    struct rebind
    { typedef allocator<_Tp1> other; };

    allocator() throw() { }

    allocator(const allocator&) throw() { }

    template<typename _Tp1>
    allocator(const allocator<_Tp1>&) throw() { }
};

template<typename T>
void f()
{
    typedef allocator<int> alloc1_t;

    typedef typename alloc1_t::template rebind<double> binder_t;
    typedef typename binder_t::other alloc2_t;

    alloc1_t a1;
    alloc2_t a3(a1);
}

g++ -v -W -Wall a.C
Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/specs
Configured with: ../gcc/configure --enable-threads=posix --enable-languages=c,c++,f77,objc --enable-__cxa_atexit --enable-debug
Thread model: posix
gcc version 3.4 20030806 (experimental)
 /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4/cc1plus -quiet -v -D_GNU_SOURCE a.C -quiet -dumpbase a.C -mtune=pentiumpro -auxbase a -W -Wall -version -o /tmp/ccW5FFki.s
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../include/c++/3.4
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../include/c++/3.4/i686-pc-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../include/c++/3.4/backward
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/include
 /usr/include
End of search list.
GNU C++ version 3.4 20030806 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 3.4 20030806 (experimental).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=31899
a.C: In function `void f()':
a.C:22: error: no type named `other' in `struct f()::binder_t'
a.C:22: error: ISO C++ forbids declaration of `alloc2_t' with no type

Compilation exited abnormally with code 1 at Wed Aug 13 00:49:53
Comment 1 Wolfgang Bangerth 2003-08-18 21:43:46 UTC
Confirmed. I guess both the "typename" as well as the "template" in the typedef for 
binder_t are unnecessary, but that doesn't change a thing. 
 
Here's something shorter: 
----------------------------------- 
template <typename T> struct A { 
    template<typename S> struct B { typedef A<S> X; }; 
 
}; 
 
template<typename> void f() { 
    typedef A<int>::B<double>::X X; 
} 
 
template void f<int> (); 
------------------------------------------------ 
with present mainline, we get 
tmp/g> ../build-gcc/gcc-install/bin/c++ -c x.cc 
x.cc: In function `void f()': 
x.cc:7: error: expected init-declarator 
x.cc:7: error: expected `,' or `;' 
 
If we make the typedef line read 
    typedef typename A<int>::B<double>::X X; 
we get instead 
tmp/g> ../build-gcc/gcc-install/bin/c++ -c x.cc 
x.cc: In function `void f()': 
x.cc:7: error: no type named `X' in `struct A<int>::B<double>' 
x.cc:7: error: ISO C++ forbids declaration of `X' with no type 
 
That's certainly not right, and a regression. 
 
W. 
Comment 2 Andrew Pinski 2003-08-18 22:21:27 UTC
From Phil's regression hunter: Search converges between 2002-12-27-trunk (#177) and 2002-
12-28-trunk (#178).

Looks like the new parse caused this.

Adding the typename gives a different date: Search converges between 2003-01-29-trunk (#208) 
and 2003-01-30-trunk (#209).

If I just add a template I get the first date, If I add both a typename and a template I get the second 
date.
Comment 3 CVS Commits 2003-09-01 19:18:06 UTC
Subject: Bug 11972

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-09-01 19:18:03

Modified files:
	gcc/cp         : ChangeLog call.c cp-tree.h decl.c pt.c typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/init: ref9.C 
	gcc/testsuite/g++.dg/template: nested4.C 

Log message:
	PR c++/12114
	* g++.dg/init/ref9.C: New test.
	
	PR c++/11972
	* g++.dg/template/nested4.C: New test.
	
	PR c++/12114
	* cp-tree.h (initialize_reference): Change prototype.
	* call.c (initialize_reference): Add cleanup parameter.
	* decl.c (grok_reference_init): Likewise.
	(check_initializer): Likewise.
	(cp_finish_decl): Insert a CLEANUP_STMT if necessary.
	(duplicate_decls): When replacing an anticipated builtin, do not
	honor TREE_NOTHROW.
	* typeck.c (convert_for_initialization): Correct call to
	initialize_reference.
	
	PR c++/11972
	* pt.c (dependent_type_p_r): Pass only the innermost template
	arguments to any_dependent_template_arguments_p.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3635&r2=1.3636
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.427&r2=1.428
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.908&r2=1.909
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1119&r2=1.1120
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.768&r2=1.769
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.496&r2=1.497
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3015&r2=1.3016
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ref9.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/nested4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Mark Mitchell 2003-09-01 20:56:42 UTC
Fixed in GCC 3.4.