Bug 25836 - [3.4 Regression] G++ does not allow a conversion of templated types
Summary: [3.4 Regression] G++ does not allow a conversion of templated types
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.2
: P3 normal
Target Milestone: 4.0.3
Assignee: Mark Mitchell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2006-01-18 02:57 UTC by jjamison
Modified: 2006-01-19 07:48 UTC (History)
5 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work: 3.3.3
Known to fail: 3.4.0 4.0.0 4.1.0 4.2.0
Last reconfirmed: 2006-01-18 03:17:34


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jjamison 2006-01-18 02:57:53 UTC
[jjamison@manzanita ~/harmonia/src-main/langs2/java/delta]$ /usr/misc/pkg/gcc-4.0.2/bin/g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.2/configure --prefix=/usr/misc/pkg/gcc-4.0.2 --enable-shared --enable-threads=posix --with-system-zlib --with-gnu-as --with-as=/usr/misc/pkg/binutils-2.16/bin/as --with-gnu-ld --with-ld=/usr/misc/pkg/binutils-2.16/bin/ld --enable-__cxa_atexit --enable-languages=c,c++
Thread model: posix
gcc version 4.0.2


Given the following code:
-----------Start Here-----------
template <class T>
class Iter {};

template <class T>
class SubIter : public Iter<T> {
   void insert(T);
};

class GraphBase {
public:
   class Node;
};

template<class T>
class Graph : public GraphBase {
   class Inner {
      Iter<typename Graph<T>::Node*> *get();
   };
};

template<class T>
Iter<typename Graph<T>::Node*> *Graph<T>::Inner::get() {
   SubIter<typename Graph<T>::Node*> *iter;
   iter->insert(0);
}

int main() {
   Iter<Graph<int>::Node*> *n2_iter = new SubIter<Graph<int>::Node*>();
}
------------End Here------------

Compile as follows:
-----------Start Here-----------
[jjamison@manzanita ~]$ /usr/misc/pkg/gcc-4.0.2/bin/g++ -Wall /tmp/bug.cc
/tmp/bug.cc: In function ‘int main()’:
/tmp/bug.cc:34: error: cannot convert ‘SubIter<GraphBase::Node*>*’ to ‘Iter<GraphBase::Node*>*’ in initialization
/tmp/bug.cc:34: warning: unused variable ‘n2_iter’
------------End Here------------

However, this conversion should be allowed.  Using other types
as the template parameter in the offending line shows the assignment
is allowable in ordinary circumstances.

Notes:
- Replacing `typename Graph<JavaType>::Node*'
    with `GraphBase::Node*' everywhere prevents the error.
- Making `get' a member of `Graph' instead of `Inner' prevents the error.
- Changing `get' to have a void return value prevents the error.
- Commenting out the `iter->insert(0);' line prevents the error.
Comment 1 jjamison 2006-01-18 03:03:03 UTC
Also, the behavior is the same for gcc versions 4.0.1, 4.0.0, 3.4.4, and 3.4.3.
gcc version 3.3.4 does not appear to have the bug.
Comment 2 Andrew Pinski 2006-01-18 03:17:34 UTC
Confirmed, this is a weird failure.
Comment 3 Andrew Pinski 2006-01-18 03:19:48 UTC
Could you do a regression hunt on this bug?
Comment 4 Janis Johnson 2006-01-18 21:24:28 UTC
A regression hunt on powerpc-linux using the submitter's testcase identified the following very large patch:

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

r69130 | mmitchel | 2003-07-09 08:48:08 +0000 (Wed, 09 Jul 2003)
Comment 5 Mark Mitchell 2006-01-19 06:53:03 UTC
Subject: Bug 25836

Author: mmitchel
Date: Thu Jan 19 06:52:56 2006
New Revision: 109943

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109943
Log:
	PR c++/25836
	* cp-tree.h (push_class_stack): New function.
	(pop_class_stack): Likewise.
	* class.c (class_stack_node): Add hidden field.
	(pushclass): Clear it.
	(push_class_stack): New function.
	(pop_class_stack): Likewise.
	(currently_open_class): Ignore hidden classes.
	(currently_open_derived_class): Likewise.
	* name-lookup.c (push_to_top_level): Call push_class_stack.
	(pop_from_top_level): Call pop_class_stack.
	PR c++/25836
	* g++.dg/template/init6.C: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/init6.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/class.c
    branches/gcc-4_1-branch/gcc/cp/cp-tree.h
    branches/gcc-4_1-branch/gcc/cp/name-lookup.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 6 Mark Mitchell 2006-01-19 06:53:40 UTC
Subject: Bug 25836

Author: mmitchel
Date: Thu Jan 19 06:53:34 2006
New Revision: 109944

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109944
Log:
	PR c++/25836
	* cp-tree.h (push_class_stack): New function.
	(pop_class_stack): Likewise.
	* class.c (class_stack_node): Add hidden field.
	(pushclass): Clear it.
	(push_class_stack): New function.
	(pop_class_stack): Likewise.
	(currently_open_class): Ignore hidden classes.
	(currently_open_derived_class): Likewise.
	* name-lookup.c (push_to_top_level): Call push_class_stack.
	(pop_from_top_level): Call pop_class_stack.
	PR c++/25836
	* g++.dg/template/init6.C: New test.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/template/init6.C
Modified:
    branches/gcc-4_0-branch/gcc/cp/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/class.c
    branches/gcc-4_0-branch/gcc/cp/cp-tree.h
    branches/gcc-4_0-branch/gcc/cp/name-lookup.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 7 Mark Mitchell 2006-01-19 06:55:57 UTC
Subject: Bug 25836

Author: mmitchel
Date: Thu Jan 19 06:55:53 2006
New Revision: 109945

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109945
Log:
	PR c++/25836
	* cp-tree.h (push_class_stack): New function.
	(pop_class_stack): Likewise.
	* class.c (class_stack_node): Add hidden field.
	(pushclass): Clear it.
	(push_class_stack): New function.
	(pop_class_stack): Likewise.
	(currently_open_class): Ignore hidden classes.
	(currently_open_derived_class): Likewise.
	* name-lookup.c (push_to_top_level): Call push_class_stack.
	(pop_from_top_level): Call pop_class_stack.
	PR c++/25836
	* g++.dg/template/init6.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/template/init6.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Mark Mitchell 2006-01-19 06:59:13 UTC
Fixed in 4.0.3.
Comment 9 Gabriel Dos Reis 2006-01-19 07:48:44 UTC
Fixed in 4.0.3 and higher.  Won't fix in 3.4.x