This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in g++


Sorry I was not able to use GNATS.

Here is my bug report:

System: Linux
GCC-version: 2.95.2

Define a template class with a corresponding friend:

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};

void f(A<int> x) {x.a++;};     

you get a warning, but the code works. Now put the whole thing in a namespace:

namespace X {

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};


void f(A<int> x) {x.a++;};    
}  

Now you get an error. f can use x.a 
(`int X::A<int>::a' is private)

If you put a function declaration befor the defintion of f
namespace X {

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};

void f(A<int> x);             
void f(A<int> x) {x.a++;};    

}  

the code works again.

if you define f ouside the namespace

namespace X {

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};


}  
using namespace X;
void f(A<int> x) {x.a++;}; 

You get an Internal compiler error 378

I have no idea what is the problem.

Good bye


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]