Bug 18353 - g++ 2.96 confused by template friends
g++ 2.96 confused by template friends
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  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:
Environment:
Last Closed: 2000-10-04 15:08:49 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
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-1.1.2.9) 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
{
public:
    int rows, cols;

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

    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>
TGRID<TYPE>::~TGRID()
{
}


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

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


#endif


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.