This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Yet another template bug in gcc-2.95.1
- To: Peter dot Vanroose at esat dot kuleuven dot ac dot be, gcc-bugs at gcc dot gnu dot org
- Subject: Yet another template bug in gcc-2.95.1
- From: Wolfgang Glas <Wolfgang dot Glas at hfm dot tu-graz dot ac dot at>
- Date: Tue, 24 Aug 1999 10:00:10 +0200
- Organization: TU-Graz
- References: <37C173AE.B4EE585@esat.kuleuven.ac.be>
Hi there,
I have just been further distilling a bug report from Peter Vanroose, which he
sent to the newsgroup gnu.g++.bug.
The main problem is that the member function operators interact with the
friend operators although they take different arguments.
//------------file: friend.cc-------------------------------------------------
typedef long int ptrdiff_t;
// Three forward declarations, which are necessary to conform with
// the new ANSI C++ standard. The template functions must be declared
// before they are used in a friend specification.
template <class RandomAccessIterator> class _r__It;
template <class RandomAccessIterator>
ptrdiff_t operator- (const _r__It <RandomAccessIterator>& x,
const _r__It <RandomAccessIterator>& y);
template <class RandomAccessIterator>
_r__It<RandomAccessIterator> operator+ (ptrdiff_t n,
const _r__It <RandomAccessIterator>& x);
template <class RandomAccessIterator>
class _r__It {
typedef ptrdiff_t distance_type;
typedef _r__It <RandomAccessIterator> self;
// now I bring in the friends...
friend distance_type operator- <> (const self& x, const self& y);
friend self operator+ <> (distance_type n, const self& x);
protected:
RandomAccessIterator current;
public:
_r__It () {}
_r__It (const RandomAccessIterator& x) : current(x) {}
// These are two different +,- operators, which badly interact with the
// friends from above in gcc-2.95.1 ......
#ifdef MORE_OPERATORS
self operator+(distance_type n) const {
return self(current - n);
}
self operator-(distance_type n) const {
return self(current + n);
}
#endif
};
template class _r__It < bool const *>;
template class _r__It < bool *>;
//------------end of file: friend.cc------------------------------------------
---------compile session------------
/home/wglas/CC/this_and_that > gcc -v
Reading specs from /usr/local/lib/gcc-lib/mips-sgi-irix6.5/2.95.1/specs
gcc version 2.95.1 19990816 (release)
/home/wglas/CC/this_and_that > gcc -c friend.cc
/home/wglas/CC/this_and_that > gcc -DMORE_OPERATORS -c friend.cc
friend.cc: In instantiation of `_r__It<const bool *>':
friend.cc:46: instantiated from here
friend.cc:24: invalid use of undefined type `class _r__It<const bool *>'
friend.cc:44: forward declaration of `class _r__It<const bool *>'
friend.cc:23: invalid use of undefined type `class _r__It<const bool *>'
friend.cc:44: forward declaration of `class _r__It<const bool *>'
friend.cc: In instantiation of `_r__It<bool *>':
friend.cc:47: instantiated from here
friend.cc:24: invalid use of undefined type `class _r__It<bool *>'
friend.cc:44: forward declaration of `class _r__It<bool *>'
friend.cc:23: invalid use of undefined type `class _r__It<bool *>'
friend.cc:44: forward declaration of `class _r__It<bool *>'
/home/wglas/CC/this_and_that > gcc -Vegcs-2.91.66 -v
Reading specs from /usr/local/lib/gcc-lib/mips-sgi-irix6.5/egcs-2.91.66/specs
gcc driver version 2.95.1 19990816 (release) executing gcc version egcs-2.91.66
/home/wglas/CC/this_and_that > gcc -Vegcs-2.91.66 -DMORE_OPERATORS -c friend.cc
------end of compile session--------
Maybe this helps to find out more about template problems with gcc-2.95.1
Wolfgang
--
Mag. Wolfgang Glas
Institut fuer hydraulische Stroemungsmaschinen
Kopernikusgasse 24 Phone:++43/316/873/7578
A-8010 Graz Fax: ++43/316/873/7577
mailto:Wolfgang.Glas@hfm.tu-graz.ac.at
http://fhysmsg01.tu-graz.ac.at/Wolfgang.Glas/