Bug 18353 - g++ 2.96 confused by template friends
Summary: g++ 2.96 confused by template friends
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
(Show other bugs)
Version: 7.0
Hardware: i386 Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2000-10-04 19:08 UTC by Need Real Name
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2000-10-04 19:08:49 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Need Real Name 2000-10-04 19:08:47 UTC
The following code used to compile under RH6.2 and still compiles with
egcs++ (from compat-egcs-c++-6.2- under RH7.0. It does not compile
under RH7.0 with g++ 2.96. The errors are reported below the sample code.

#ifndef _TGRID_CC
#define _TGRID_CC

#include <fstream.h>
#include <stdlib.h>

template <class TYPE>
class TGRID
    int rows, cols;

    TGRID(int R=0, int C=0);

    template<class TYPE>
    friend ostream & operator<<(ostream & OUT, TGRID<TYPE> & G);

    template<class TYPE>
    friend istream & operator>>(istream & IN, TGRID<TYPE> & G);


template <class TYPE>
TGRID<TYPE>::TGRID(int R, int C)
    : rows(R), cols(C)

template <class TYPE>

template <class TYPE>
ostream & operator<<(ostream & OUT, TGRID<TYPE> & G)
    return OUT;

template <class TYPE>
istream & operator>>(istream & OUT, TGRID<TYPE> & G)
    return IN;


479) silviu:~/TESTg++> g++ -v 
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)
480) silviu:~/TESTg++> g++ -c tgrid.cc
tgrid.cc:17: declaration of `class TYPE'
tgrid.cc:8:  shadows template parm `class TYPE'
tgrid.cc:20: declaration of `class TYPE'
tgrid.cc:8:  shadows template parm `class TYPE'

I understand there is a chance that my code does not comply with the C++
standard, while gcc and g++ try to adhere to it, but in this case some
warnings and some documentation about the new standard would have helped.
The only docs with g++-2.96 are /usr/share/doc/gcc-c++-2.96/ChangeLog*

Silviu Minut

Comment 1 Jakub Jelinek 2000-10-06 09:53:49 UTC
C++ standard sais:
A template-parameter shall not be redeclared within its
scope (including nested scopes).
So your testcase is wrong, just fix it up and be done with it.
g++ 2.96 we ship is very close to the upcoming g++ 3 API, so you'd have to
change your code anyway.
As for documentation, there were really too many changes in the C++ frontend
to document them all, the best documentation are C++ and C standards.

Note You need to log in before you can comment on or make changes to this bug.