public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y>
@ 2003-09-27 3:14 sean dot gies at discreet dot com
2003-09-27 3:27 ` [Bug c++/12429] " pinskia at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: sean dot gies at discreet dot com @ 2003-09-27 3:14 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12429
Summary: Template class Foo<X> cannot access private members of
Foo<Y>
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sean dot gies at discreet dot com
CC: gcc-bugs at gcc dot gnu dot org
Member functions of template classes cannot access protected or private members of a different
specialization of itself, nor can a friendship be declared to allow the access.
The only workaround involves hacking the public interface of the template class.
For example, private member function Bar(int) of class Foo<float> cannot call Bar(int) of class
Foo<int>:
template <class T> class Foo {
template <class F> friend class Foo<F>; // This attempted work-around also fails
void Bar(int x=0) {if (x<4) Foo<int>().Bar(x+1);}
public:
void Test() {Bar();}
};
int main(int argc, char** argv) {
Foo<float>().Test();
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/12429] Template class Foo<X> cannot access private members of Foo<Y>
2003-09-27 3:14 [Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y> sean dot gies at discreet dot com
@ 2003-09-27 3:27 ` pinskia at gcc dot gnu dot org
2003-09-27 6:51 ` pinskia at gcc dot gnu dot org
2003-09-29 20:37 ` sean dot gies at discreet dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-09-27 3:27 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12429
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-09-27 01:54 -------
I think the code is invalid as different specialization are really different classes.
The way to fix this is make Foo<int> a friend.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/12429] Template class Foo<X> cannot access private members of Foo<Y>
2003-09-27 3:14 [Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y> sean dot gies at discreet dot com
2003-09-27 3:27 ` [Bug c++/12429] " pinskia at gcc dot gnu dot org
@ 2003-09-27 6:51 ` pinskia at gcc dot gnu dot org
2003-09-29 20:37 ` sean dot gies at discreet dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-09-27 6:51 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12429
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-09-27 05:49 -------
Here is how to fix you code (yes I was right about "different specialization are really
different classes", the problem was that you were trying make friends with specializations
which is wrong):
template <class T> class Foo {
template <class Y> friend class Foo;
void Bar(int x=0) {if (x<4) Foo<int>().Bar(x+1);}
public:
void Test() {Bar();}
};
int main(int argc, char** argv) {
Foo<float>().Test();
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/12429] Template class Foo<X> cannot access private members of Foo<Y>
2003-09-27 3:14 [Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y> sean dot gies at discreet dot com
2003-09-27 3:27 ` [Bug c++/12429] " pinskia at gcc dot gnu dot org
2003-09-27 6:51 ` pinskia at gcc dot gnu dot org
@ 2003-09-29 20:37 ` sean dot gies at discreet dot com
2 siblings, 0 replies; 4+ messages in thread
From: sean dot gies at discreet dot com @ 2003-09-29 20:37 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12429
------- Additional Comments From sean dot gies at discreet dot com 2003-09-29 19:45 -------
Subject: Re: Template class Foo<X> cannot access private members of Foo<Y>
Thank you for the fix. Just when I thought I finally understood
templates. :)
-Sean
On Friday, September 26, 2003, at 10:49 PM, pinskia at gcc dot gnu dot
org wrote:
> PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT*
> gcc-bugs@gcc.gnu.org.
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12429
>
>
> pinskia at gcc dot gnu dot org changed:
>
> What |Removed |Added
> -----------------------------------------------------------------------
> -----
> Status|UNCONFIRMED |RESOLVED
> Resolution| |INVALID
>
>
> ------- Additional Comments From pinskia at gcc dot gnu dot org
> 2003-09-27 05:49 -------
> Here is how to fix you code (yes I was right about "different
> specialization are really
> different classes", the problem was that you were trying make friends
> with specializations
> which is wrong):
> template <class T> class Foo {
> template <class Y> friend class Foo;
> void Bar(int x=0) {if (x<4) Foo<int>().Bar(x+1);}
> public:
> void Test() {Bar();}
> };
> int main(int argc, char** argv) {
> Foo<float>().Test();
> }
>
>
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-09-29 19:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-27 3:14 [Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y> sean dot gies at discreet dot com
2003-09-27 3:27 ` [Bug c++/12429] " pinskia at gcc dot gnu dot org
2003-09-27 6:51 ` pinskia at gcc dot gnu dot org
2003-09-29 20:37 ` sean dot gies at discreet dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).