public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug 45770] (c++) New: global access allowance exceeds that of derived class
@ 2010-09-23 23:11 MichieldeB at aim dot com
2010-09-23 23:16 ` [Bug 45770] (c++) " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: MichieldeB at aim dot com @ 2010-09-23 23:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45770
Summary: global access allowance exceeds that of derived class
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: MichieldeB@aim.com
// g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
// Copyright (C) 2009 Free Software Foundation, Inc.
// This is free software; see the source for copying conditions. There is NO
// warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
class A
{
friend class B;
public:
A(int i) { a = i; }
private:
A() { a = 0; }
int a;
};
class B : private A // making protected will eliminate the below problem
{
public:
B(int i) : A () { a = i >> 1; b = i & 1; }
private:
bool b;
};
class C : public B
{
public:
C() : B(4) { A foo(3); } // functions of B may not have local variables A
};
main () { A bar(3); } // main may have local variables A
--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug 45770] (c++) global access allowance exceeds that of derived class
2010-09-23 23:11 [Bug 45770] (c++) New: global access allowance exceeds that of derived class MichieldeB at aim dot com
@ 2010-09-23 23:16 ` pinskia at gcc dot gnu.org
2010-09-24 21:58 ` [Bug c++/45770] " MichieldeB at aim dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-09-23 23:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45770
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-09-23 23:16:16 UTC ---
This is correct as the A here is injected via the inheirtance of the class. If
you want to use the name the global A, use ::A.
--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/45770] global access allowance exceeds that of derived class
2010-09-23 23:11 [Bug 45770] (c++) New: global access allowance exceeds that of derived class MichieldeB at aim dot com
2010-09-23 23:16 ` [Bug 45770] (c++) " pinskia at gcc dot gnu.org
2010-09-24 21:58 ` [Bug c++/45770] " MichieldeB at aim dot com
@ 2010-09-24 21:58 ` pinskia at gcc dot gnu.org
2010-09-26 22:31 ` MichieldeB at aim dot com
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-09-24 21:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45770
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-09-24 21:58:44 UTC ---
> access of locals
Huh? That is not what I am saying. What I am saying is that A names (inside
C) the injected name in B which is private.
The reason why:
template <class T, class U> class D : private T
{
D(int i) : T(i) { U u; }
};
template class D<A,A>; // local A gets global access rights
--- CUT ---
Works is because the names you are using are T and U and not A.
--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/45770] global access allowance exceeds that of derived class
2010-09-23 23:11 [Bug 45770] (c++) New: global access allowance exceeds that of derived class MichieldeB at aim dot com
2010-09-23 23:16 ` [Bug 45770] (c++) " pinskia at gcc dot gnu.org
@ 2010-09-24 21:58 ` MichieldeB at aim dot com
2010-09-24 21:58 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: MichieldeB at aim dot com @ 2010-09-24 21:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45770
MichieldeB at aim dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
--- Comment #2 from MichieldeB at aim dot com 2010-09-24 21:53:56 UTC ---
// If the access of locals should be inherited, then the following is a bug.
// g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
// Copyright (C) 2009 Free Software Foundation, Inc.
// This is free software; see the source for copying conditions. There is NO
// warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
class A
{
friend class B;
public:
A(int i) { a = i; }
private:
A() { a = 0; }
int a;
};
class B : private A // making protected will allow local variables A below
{
public:
B(int i) : A () { a = i >> 1; b = i & 1; }
private:
bool b;
};
class C : public B
{
public:
C() : B(4) { ::A foo(3); } // functions of B may have local variables ::A
// but not A
};
template <class T, class U> class D : private T
{
D(int i) : T(i) { U u; }
};
template class D<A,A>; // local A gets global access rights
main () { ::A bar(3); } // main may have local variables A
--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/45770] global access allowance exceeds that of derived class
2010-09-23 23:11 [Bug 45770] (c++) New: global access allowance exceeds that of derived class MichieldeB at aim dot com
` (2 preceding siblings ...)
2010-09-24 21:58 ` pinskia at gcc dot gnu.org
@ 2010-09-26 22:31 ` MichieldeB at aim dot com
2010-09-26 22:40 ` paolo.carlini at oracle dot com
2010-09-27 7:18 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: MichieldeB at aim dot com @ 2010-09-26 22:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45770
MichieldeB at aim dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
--- Comment #4 from MichieldeB at aim dot com 2010-09-26 18:14:26 UTC ---
My last counterexample was invalid, sorry. Furthermore, the problem does not
seem a template problem. I now have an example where the local object has lower
rights than the inherited object, thus no access inheritance for the local.
// g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
// Copyright (C) 2009 Free Software Foundation, Inc.
// This is free software; see the source for copying conditions. There is NO
// warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
class A
{
friend class B;
public:
A(int i) { a = i; }
protected:
A(int i, int j) { a = i ^ j; }
private:
A() { a = 0; }
int a;
};
class B : private A // making protected will allow local variables A below
{
public:
B(int i) : A () { a = i >> 1; b = i & 1; }
private:
bool b;
};
class C : public B
{
public:
C() : B(4) { ::A foo(3); } // functions of B may have local variables ::A
// but not A
};
class D : public A
{
friend class D;
D(int i, int j) : A(i,j)
{
A d(i,j); // friend class D of class D has no inherited rights here
// note that friends do not have inherited objects in general
}
};
main () { A bar(3); } // main may have local variables A
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/45770] global access allowance exceeds that of derived class
2010-09-23 23:11 [Bug 45770] (c++) New: global access allowance exceeds that of derived class MichieldeB at aim dot com
` (3 preceding siblings ...)
2010-09-26 22:31 ` MichieldeB at aim dot com
@ 2010-09-26 22:40 ` paolo.carlini at oracle dot com
2010-09-27 7:18 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-09-26 22:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45770
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |paolo.carlini at oracle dot
| |com
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-09-26 18:25:29 UTC ---
Without having looked into your last snippet, I note that the Intel Compiler,
VC++, and Comeau also reject it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/45770] global access allowance exceeds that of derived class
2010-09-23 23:11 [Bug 45770] (c++) New: global access allowance exceeds that of derived class MichieldeB at aim dot com
` (4 preceding siblings ...)
2010-09-26 22:40 ` paolo.carlini at oracle dot com
@ 2010-09-27 7:18 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2010-09-27 7:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45770
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-09-26 19:36:39 UTC ---
(In reply to comment #4)
>
> class A
> {
>
> friend class B;
>
> public:
> A(int i) { a = i; }
>
> protected:
> A(int i, int j) { a = i ^ j; }
>
> private:
> A() { a = 0; }
> int a;
>
> };
>
> class B : private A // making protected will allow local variables A below
> {
>
> public:
> B(int i) : A () { a = i >> 1; b = i & 1; }
B is a friend of A so can call the private constructor.
> private:
> bool b;
>
> };
>
> class C : public B
> {
>
> public:
> C() : B(4) { ::A foo(3); } // functions of B may have local variables ::A
> // but not A
A(int) is public, so it can be called
> };
>
> class D : public A
> {
> friend class D;
What is this supposed to do?
>
> D(int i, int j) : A(i,j)
A(int, int) is protected, so D can call it on its base sub-object
> {
> A d(i,j); // friend class D of class D has no inherited rights here
> // note that friends do not have inherited objects in general
The object 'd' is not a sub-object of D, so there is no access to that
constructor from D's member functions.
> }
> };
>
> main () { A bar(3); } // main may have local variables A
That constructor is public, so of course it can.
Your example is not valid C++, that's not a problem with GCC.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-09-26 19:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-23 23:11 [Bug 45770] (c++) New: global access allowance exceeds that of derived class MichieldeB at aim dot com
2010-09-23 23:16 ` [Bug 45770] (c++) " pinskia at gcc dot gnu.org
2010-09-24 21:58 ` [Bug c++/45770] " MichieldeB at aim dot com
2010-09-24 21:58 ` pinskia at gcc dot gnu.org
2010-09-26 22:31 ` MichieldeB at aim dot com
2010-09-26 22:40 ` paolo.carlini at oracle dot com
2010-09-27 7:18 ` redi at gcc dot gnu.org
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).