Qualified friends
Nathan Sidwell
nathan@acm.org
Sun Feb 28 23:30:00 GMT 1999
Martin v. Loewis wrote:
> Correct. I've updated the previous patch; you'll have to reverse that
> one before applying this one. I guess I make a test case for
> everything once you don't find new problems, anymore :-)
Yup, that's all ok now - hurrah!
I attach the autoconf test I'm now using to check these features, feel free to
incorporate it into a testcase (you'll see your ambiguous case in there
anyway).
Unpatched snapshot gives,
nathan@manao:1066>ss-g++ -c alien.C
alien.C:5: parse error before `('
alien.C: In function `void foo(class S *)':
alien.C:9: member `m' is a private member of class `S'
alien.C: At top level:
alien.C:28: declaration of `bink(L::U *)' not in a namespace surrounding `M'
alien.C:48: parse error before `)'
alien.C:49: parse error before `)'
alien.C:60: parse error before `('
alien.C:65: parse error before `('
alien.C:79: parse error before `('
alien.C:80: declaration of `bonk(K::T *)' not in a namespace surrounding `::'
alien.C: In function `void bink(class K::T *)':
alien.C:86: member `m' is a private member of class `K::T'
alien.C: In function `void bonk(class K::T *)':
alien.C:89: member `m' is a private member of class `K::T'
patched compiler gives no diagnostics
nathan@manao:1067>devel-g++ -c alien.C
> We had that in the beginning, until the global namespace appeared in
> the assembler output and the back-end people started complaining that
> they don't want see namespace nodes anywhere. This was the change
thanks for the background info on why it was changed.
> Given the confusion produced last time, I doubt that such a patch is
> accepted. I personally wouldn't object, provided that the fix is
> 'perfect' - there is no reason to change one hack into another.
Ok, I'll decline to `clean' this up, people like you (Martin) and Jason are in
a much better position to understand the issues. IMHO, this hack is getting
uglier and uglier -- we're lying to the compiler and it'll bite us!
Once again, thanks for taking the time to get these alien friends working.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
// try a global friend
class S;
void foo(S *);
class S {
friend void ::foo(S *);
int m;
};
void foo(S *s) {
s->m = 1;
}
// try a namespace friend
class T;
namespace N {void bar(T *);}
class T {
friend void N::bar(T *);
int m;
};
void N::bar(T *t) {
t->m = 1;
}
// try a different namespace friend
namespace L {class U;}
namespace M {void bink(L::U *);}
namespace L {
class U {
friend void M::bink(U *);
int m;
};
}
void M::bink(L::U *u) {
u->m = 1;
}
// try an ambiguous case
struct A {
struct B {};
};
A::B C();
namespace B {
A C();
}
class Test {
friend A (::B::C)(); // Ok
friend A::B (::C)(); // Ok
};
// global friend from a namespace
namespace K {
class S;
}
void baz(K::S *);
namespace K {
class S {
friend void ::baz(S *);
int m;
};
}
void ::baz(K::S *ptr) {
ptr->m = 1;
}
// std friend from a namespace
namespace K {
class T;
}
namespace std {
void bink(K::T *);
void bonk(K::T *);
}
namespace K {
class T {
friend void ::std::bink(T *);
friend void std::bonk(T *);
int m;
};
}
void std::bink(K::T *ptr) {
ptr->m = 1;
}
void std::bonk(K::T *ptr) {
ptr->m = 1;
}
More information about the Gcc-bugs
mailing list