Bug 38501 - typedef confuses the name of the template and the name of result
Summary: typedef confuses the name of the template and the name of result
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-12 01:40 UTC by Feklushkin Denis
Modified: 2008-12-12 01:46 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
demo (156 bytes, text/plain)
2008-12-12 01:42 UTC, Feklushkin Denis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Feklushkin Denis 2008-12-12 01:40:48 UTC
typedef confuses the name of the template and the name of result:

sh-3.2$ cat tloop_iterator.h
#ifndef TLOOP_ITERATOR_H_
#define TLOOP_ITERATOR_H_

#include <list>

template<typename T>
struct loop_iterator : public T::iterator
{ };


template <typename T>
struct list : std::list<T>
{
  typedef loop_iterator<list> loop_iterator;
};

#endif

Compiling this file:

sh-3.2$ g++-4.1  tloop_iterator.h
sh-3.2$ g++-4.2  tloop_iterator.h

all right, but:

sh-3.2$ g++-4.3  tloop_iterator.h
tloop_iterator.h:14: error: declaration of ‘typedef struct loop_iterator<list<T> > list<T>::loop_iterator’
tloop_iterator.h:8: error: changes meaning of ‘loop_iterator’ from ‘struct loop_iterator<list<T> >’

sh-3.2$ g++-4.3 --version
g++-4.3 (Debian 4.3.2-1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My system is Debian GLU/Linux Lenny

Version 4.3.1 also has this problem
Comment 1 Feklushkin Denis 2008-12-12 01:42:35 UTC
Created attachment 16896 [details]
demo
Comment 2 Andrew Pinski 2008-12-12 01:46:46 UTC
No GCC 4.3 and above is doing the correct thing.  This code is invalid but no diagnostic is required by the C++ standard.

See <http://gcc.gnu.org/gcc-4.3/porting_to.html>:
Name lookup changes

GCC by default no longer accepts code such as

template <class _Tp> class auto_ptr {};
template <class _Tp>
struct counted_ptr
{
  auto_ptr<_Tp> auto_ptr();
};
but will issue the diagnostic

error: declaration of 'auto_ptr<_Tp> counted_ptr<_Tp>::auto_ptr()'
error: changes meaning of 'auto_ptr' from 'class auto_ptr<_Tp>'
The reference to struct auto_ptr needs to be qualified here, or the name of the member function changed to be unambiguous.

template <class _Tp> class auto_ptr {};
template <class _Tp>
struct counted_ptr
{
  ::auto_ptr<_Tp> auto_ptr();
};
In addition, -fpermissive can be used as a temporary workaround to convert the error into a warning until the code is fixed. Note that then in some case name lookup will not be standard conforming.