public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker
@ 2004-05-19 17:30 gccbugs at contacts dot eelis dot net
2004-05-19 17:32 ` [Bug c++/15531] " bangerth at dealii dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: gccbugs at contacts dot eelis dot net @ 2004-05-19 17:30 UTC (permalink / raw)
To: gcc-bugs
Consider the following snippet:
struct Base
{
virtual ~Base () {}
};
class Derived : Base
{
friend int main ();
};
#include <cassert>
int main ()
{
Base * p = new Derived;
assert(dynamic_cast<Derived *>(p)); // fails
}
When Derived is changed to publically inherit Base, the dynamic_cast succeeds.
--
Summary: dynamic_cast fails (at runtime) when dependant on
friendship of invoker
Product: gcc
Version: 3.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gccbugs at contacts dot eelis dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i486-slackware-linux
GCC target triplet: i486-slackware-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
@ 2004-05-19 17:32 ` bangerth at dealii dot org
2004-05-19 17:39 ` gccbugs at contacts dot eelis dot net
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: bangerth at dealii dot org @ 2004-05-19 17:32 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-05-18 23:29 -------
Of course it fails. You can't use dynamic_cast to work around access
control.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
2004-05-19 17:32 ` [Bug c++/15531] " bangerth at dealii dot org
@ 2004-05-19 17:39 ` gccbugs at contacts dot eelis dot net
2004-05-19 17:53 ` bangerth at dealii dot org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: gccbugs at contacts dot eelis dot net @ 2004-05-19 17:39 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gccbugs at contacts dot eelis dot net 2004-05-18 23:32 -------
Which access control are you referring to?
main() has been granted friendship by Derived, and in the snippet even creates a
Derived instance.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
` (2 preceding siblings ...)
2004-05-19 17:53 ` bangerth at dealii dot org
@ 2004-05-19 17:53 ` Gabriel Dos Reis
2004-05-19 18:04 ` [Bug c++/15531] " gdr at integrable-solutions dot net
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Dos Reis @ 2004-05-19 17:53 UTC (permalink / raw)
To: gcc-bugzilla; +Cc: gcc-bugs
"gccbugs at contacts dot eelis dot net" <gcc-bugzilla@gcc.gnu.org> writes:
| Consider the following snippet:
|
| struct Base
| {
| virtual ~Base () {}
| };
|
| class Derived : Base
| {
| friend int main ();
| };
|
| #include <cassert>
|
| int main ()
| {
| Base * p = new Derived;
|
| assert(dynamic_cast<Derived *>(p)); // fails
As required by the C++ standard. There is no way you can successfully
dynamic_cast from base class to derived class that does not publically
inherit.
| }
|
| When Derived is changed to publically inherit Base, the dynamic_cast succeeds.
Yes, that is what is required by the ISO C++ standard.
The PR is invalid.
-- Gaby
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
2004-05-19 17:32 ` [Bug c++/15531] " bangerth at dealii dot org
2004-05-19 17:39 ` gccbugs at contacts dot eelis dot net
@ 2004-05-19 17:53 ` bangerth at dealii dot org
2004-05-19 17:53 ` [Bug c++/15531] New: " Gabriel Dos Reis
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: bangerth at dealii dot org @ 2004-05-19 17:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-05-18 23:35 -------
Maybe I should be a little more explicit: the cast actually
happens inside the dynamic_cast operator, but that isn't a
friend of the two classes (and can't be made a friend). Thus,
it can't do the cast and returns zero. The fact that the
call to the dynamic_cast is inside a class that _can_ do this
is immaterial here.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
` (3 preceding siblings ...)
2004-05-19 17:53 ` [Bug c++/15531] New: " Gabriel Dos Reis
@ 2004-05-19 18:04 ` gdr at integrable-solutions dot net
2004-05-19 18:22 ` gccbugs at contacts dot eelis dot net
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: gdr at integrable-solutions dot net @ 2004-05-19 18:04 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2004-05-18 23:38 -------
Subject: Re: New: dynamic_cast fails (at runtime) when dependant on friendship of invoker
"gccbugs at contacts dot eelis dot net" <gcc-bugzilla@gcc.gnu.org> writes:
| Consider the following snippet:
|
| struct Base
| {
| virtual ~Base () {}
| };
|
| class Derived : Base
| {
| friend int main ();
| };
|
| #include <cassert>
|
| int main ()
| {
| Base * p = new Derived;
|
| assert(dynamic_cast<Derived *>(p)); // fails
As required by the C++ standard. There is no way you can successfully
dynamic_cast from base class to derived class that does not publically
inherit.
| }
|
| When Derived is changed to publically inherit Base, the dynamic_cast succeeds.
Yes, that is what is required by the ISO C++ standard.
The PR is invalid.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
` (4 preceding siblings ...)
2004-05-19 18:04 ` [Bug c++/15531] " gdr at integrable-solutions dot net
@ 2004-05-19 18:22 ` gccbugs at contacts dot eelis dot net
2004-05-19 19:05 ` gdr at integrable-solutions dot net
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: gccbugs at contacts dot eelis dot net @ 2004-05-19 18:22 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gccbugs at contacts dot eelis dot net 2004-05-18 23:43 -------
I see, thanks for clearing that up.
In this case, would it not be desirable to have gcc emit an error/warning
indicating that the cast will always fail since Base is not a public base class
of Derived?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
` (5 preceding siblings ...)
2004-05-19 18:22 ` gccbugs at contacts dot eelis dot net
@ 2004-05-19 19:05 ` gdr at integrable-solutions dot net
2004-05-20 9:08 ` bangerth at dealii dot org
2004-05-20 13:25 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: gdr at integrable-solutions dot net @ 2004-05-19 19:05 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2004-05-19 01:15 -------
Subject: Re: dynamic_cast fails (at runtime) when dependant on friendship of invoker
"gccbugs at contacts dot eelis dot net" <gcc-bugzilla@gcc.gnu.org> writes:
| I see, thanks for clearing that up.
| In this case, would it not be desirable to have gcc emit an error/warning
| indicating that the cast will always fail since Base is not a public
| base class of Derived?
yes, it could -- not in all cases -- but this is certainly a case when
the answer is known at translation time. The PR could be open as
diagnostic enhancement and the subject changed to reflect the outcome
ot this discussion.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
` (6 preceding siblings ...)
2004-05-19 19:05 ` gdr at integrable-solutions dot net
@ 2004-05-20 9:08 ` bangerth at dealii dot org
2004-05-20 13:25 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: bangerth at dealii dot org @ 2004-05-20 9:08 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-05-19 13:16 -------
I opened PR 15541 for this.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
` (7 preceding siblings ...)
2004-05-20 9:08 ` bangerth at dealii dot org
@ 2004-05-20 13:25 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-20 13:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-19 13:34 -------
Which was a dup of bug 12277.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-05-19 13:34 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-19 17:30 [Bug c++/15531] New: dynamic_cast fails (at runtime) when dependant on friendship of invoker gccbugs at contacts dot eelis dot net
2004-05-19 17:32 ` [Bug c++/15531] " bangerth at dealii dot org
2004-05-19 17:39 ` gccbugs at contacts dot eelis dot net
2004-05-19 17:53 ` bangerth at dealii dot org
2004-05-19 17:53 ` [Bug c++/15531] New: " Gabriel Dos Reis
2004-05-19 18:04 ` [Bug c++/15531] " gdr at integrable-solutions dot net
2004-05-19 18:22 ` gccbugs at contacts dot eelis dot net
2004-05-19 19:05 ` gdr at integrable-solutions dot net
2004-05-20 9:08 ` bangerth at dealii dot org
2004-05-20 13:25 ` pinskia at gcc dot gnu dot 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).