This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12229] dynamic_cast, private inheritance and friendship
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Sep 2003 01:12:54 -0000
- Subject: [Bug c++/12229] dynamic_cast, private inheritance and friendship
- References: <20030910000414.12229.shelly@InterraSystems.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12229
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
Summary|dynamic_cast in templates |dynamic_cast, private
|causes core dump in gcc |inheritance and friendship
|3.3.1 but not in gcc 2.95.3 |
------- Additional Comments From bangerth at dealii dot org 2003-09-10 01:12 -------
This one is actually much simpler than it looks like. Consider this
code:
-----------------------------
#include <cassert>
struct B {
virtual ~B() {};
};
struct D : private B {
friend class S;
};
struct S {
static void f() {
B *pB = new D();
assert (dynamic_cast<D*>(pB) != 0);
}
};
int main() {
S::f ();
}
----------------------------
When compiled with 2.95, this code survives the assert, but it doesn't
with 3.x and icc. Now, gcc 2.95 is wrong. The point is that the
compiler must allow the attempt at the dynamic_cast since S is a friend
of D, so the base class of D is visible to S. However, the
dynamic_cast then fails at run-time. And since this is exactly what
5.2.7/8 says, the testcase must yield the abort.