[Bug c++/25836] New: G++ does not allow a conversion of templated types

jjamison at cs dot berkeley dot edu gcc-bugzilla@gcc.gnu.org
Wed Jan 18 02:57:00 GMT 2006


[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.


-- 
           Summary: G++ does not allow a conversion of templated types
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jjamison at cs dot berkeley dot edu
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25836



More information about the Gcc-bugs mailing list