This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/12229] dynamic_cast, private inheritance and friendship


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]