Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 18353 - g++ 2.96 confused by template friends
g++ 2.96 confused by template friends
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2000-10-04 15:08 EDT by Need Real Name
Modified: 2008-05-01 11:37 EDT (History)
0 users

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

Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2000-10-04 15:08:47 EDT
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 05:53:49 EDT
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.