From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1590 invoked by alias); 10 Sep 2003 01:12:55 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 1583 invoked by uid 48); 10 Sep 2003 01:12:54 -0000 Date: Wed, 10 Sep 2003 01:12:00 -0000 Message-ID: <20030910011254.1582.qmail@sources.redhat.com> From: "bangerth at dealii dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20030910000414.12229.shelly@InterraSystems.com> References: <20030910000414.12229.shelly@InterraSystems.com> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/12229] dynamic_cast, private inheritance and friendship X-Bugzilla-Reason: CC X-SW-Source: 2003-09/txt/msg00807.txt.bz2 List-Id: 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 struct B { virtual ~B() {}; }; struct D : private B { friend class S; }; struct S { static void f() { B *pB = new D(); assert (dynamic_cast(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.