[Bug c++/42328] rejects valid friend
igodard at pacbell dot net
gcc-bugzilla@gcc.gnu.org
Tue Dec 8 02:16:00 GMT 2009
------- Comment #3 from igodard at pacbell dot net 2009-12-08 02:16 -------
I stand corrected about Comeau - I missed the error and only noticed the
warning. Regardless, there must be some way to solve this problem:
template<typename T, typename U>
class freeList {
public:
void foo();
};
class bar {};
class baz : protected freeList<bar, baz> {
void frob() {}
};
template<>
void freeList<bar, baz>::foo() { static_cast<baz*>(this)->frob(); }
int main() {
baz b;
return 0;
}
gets you:
s3:~/ootbc/personal/ivan$ g++ foo.cc
foo.cc: In member function Âvoid freeList<T, U>::foo() [with T = bar, U =
baz]Â:
foo.cc:14: error: ÂfreeList<bar, baz>Â is an inaccessible base of ÂbazÂ
I believe this diagnostic is legitimate. If I recall, in earlier versions of
the compiler (4.0.X? Don't remember) the template "friend" declaration in the
original report exposed the base class to the friend function and the code
(with the friend) compiled without error. Then we upgraded the compiler and it
stopped working. I thought this reflected a new bug and reported it. If in fact
the friend is invalid (just not previously caught) then fine - but then how do
you get the original cast to the base to work?
In short, if the friend declaration I wrote is illegal, how otherwise do you
turn a member function of a base class into a friend of a derived class of that
base?
I realize that helping me in my code is not your job, but any help would be
greatly appreciated. And if it is not in fact possible perhaps some of the
language mavens among you might raise the issue with the standards group,
because what I was trying is certainly a reasonable thing to want to do.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42328
More information about the Gcc-bugs
mailing list