Bug 30818 - [4.2 Regression] templates and typedefs cause function prototype not to match
Summary: [4.2 Regression] templates and typedefs cause function prototype not to match
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.2
: P2 critical
Target Milestone: 4.3.0
Assignee: Nathan Sidwell
URL:
Keywords: rejects-valid
: 30821 (view as bug list)
Depends on: 27787
Blocks:
  Show dependency treegraph
 
Reported: 2007-02-16 10:30 UTC by sschunck
Modified: 2009-03-30 21:35 UTC (History)
5 users (show)

See Also:
Host: i686-pc-linux
Target:
Build:
Known to work: 3.4.6 4.1.1 4.3.0
Known to fail: 4.1.2 4.2.0 4.2.5
Last reconfirmed: 2007-07-21 20:50:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sschunck 2007-02-16 10:30:22 UTC
the following compiled fine on gcc-3.4.6 but gives error on gcc-4.1.2

error: prototype for 'typename A<T>::B::type A<T>::B::f()' does not match any in class 'A<T>::B'
error: candidate is: typename A<T>::type A<T>::B::f()
error: template definition of non-template 'typename A<T>::B::type A<T>::B::f()'


template < typename T > 
class A 
{
        typedef int type;
        class B;
};

template < typename T >
class A<T>::B
{
        typedef typename A<T>::type type;
        type g() { return 0;}
        type f();
};

template < typename T >
typename A<T>::B::type 
A<T>::B::f() { return 0; }

( I have no vanilla gcc available, so hopefully gentoo guys did not screw up gcc-4.1.2 )

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /home/portage/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.2 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libunwind-exceptions --disable-multilib --disable-libmudflap --disable-libssp --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.1.2 (Gentoo 4.1.2)
Comment 1 Richard Biener 2007-02-16 11:25:02 UTC
EDG happily eats this.  With mainline the error looks like

t.ii:18: error: prototype for ‘typename A<T>::B::type A<T>::B::f()’ does not match any in class ‘A<T>::B’
t.ii:13: error: candidate is: typename A<T>::type A<T>::B::f()
t.ii:18: error: ‘typename A<T>::B::type A<T>::B::f()’ cannot be overloaded
t.ii:13: error: with ‘typename A<T>::type A<T>::B::f()’
t.ii:18: error: template definition of non-template ‘typename A<T>::B::type A<T>::B::f()’
Comment 2 Richard Biener 2007-02-16 13:46:54 UTC
*** Bug 30821 has been marked as a duplicate of this bug. ***
Comment 3 Janis Johnson 2007-04-23 22:26:30 UTC
A regression hunt on powerpc-linux identified this mainline patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=116409

    r116409 | nathan | 2006-08-25 09:56:07 -0700 (Fri, 25 Aug 2006)

This patch was backported to the 4.1 branch on 2006-10-18.
Comment 4 Nathan Sidwell 2007-07-21 20:50:59 UTC
testing a patch
Comment 5 Nathan Sidwell 2007-07-22 16:26:05 UTC
Subject: Bug 30818

Author: nathan
Date: Sun Jul 22 16:25:54 2007
New Revision: 126825

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126825
Log:
cp/
	PR c++/30818
	* typeck.c (structural_comptypes): No need to check
	resolve_typename_type return value here.
	* cp-tree.h (TYPENAME_IS_RESOLVING_P): New.
	* pt.c (resolve_typename_type): Follow typename typedefs.  Return
	original type rather than error_mark_node in case of failure.
	* parser.c (cp_parser_nested_name_specifier_opt): Adjust
	resolve_typename_type result check.
	(cp_parser_direct_declarator, cp_parser_head,
	cp_parser_constructor_declarator_p): Likewise.

testsuite/
	PR c++/30818
	* g++.dg/template/crash47.C: Adjust errors.
	* g++.dg/template/crash48.C: Adjust errors.
	* g++.dg/template/typename12.C: New.
	* g++.dg/template/typename13.C: New.
	* g++.dg/template/typename14.C: New.
	* g++.dg/template/typedef6.C: Adjust errors.

Added:
    trunk/gcc/testsuite/g++.dg/template/typename12.C
    trunk/gcc/testsuite/g++.dg/template/typename13.C
    trunk/gcc/testsuite/g++.dg/template/typename14.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/template/crash47.C
    trunk/gcc/testsuite/g++.dg/template/crash48.C
    trunk/gcc/testsuite/g++.dg/template/typedef6.C

Comment 6 Nathan Sidwell 2007-07-22 16:33:51 UTC
fixed with http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01644.html


	cp/
	PR c++/30818
	* typeck.c (structural_comptypes): No need to check
	resolve_typename_type return value here.
	* cp-tree.h (TYPENAME_IS_RESOLVING_P): New.
	* pt.c (resolve_typename_type): Follow typename typedefs.  Return
	original type rather than error_mark_node in case of failure.
	* parser.c (cp_parser_nested_name_specifier_opt): Adjust
	resolve_typename_type result check.
	(cp_parser_direct_declarator, cp_parser_head,
	cp_parser_constructor_declarator_p): Likewise.

	testsuite/
	PR c++/30818
	* g++.dg/template/crash47.C: Adjust errors.
	* g++.dg/template/crash48.C: Adjust errors.
	* g++.dg/template/typename12.C: New.
	* g++.dg/template/typename13.C: New.
	* g++.dg/template/typename14.C: New.
	* g++.dg/template/typedef6.C: Adjust errors.

the patch should backport painlessly to 4.2
Comment 7 Richard Biener 2007-07-23 19:24:47 UTC
Re-open, as the branches are still affected and this is a regression.
Comment 8 Joseph S. Myers 2008-07-04 21:57:25 UTC
Closing 4.1 branch.
Comment 9 Joseph S. Myers 2009-03-30 21:35:38 UTC
Closing 4.2 branch, fixed in 4.3.