public inbox for
help / color / mirror / Atom feed
From: Matthias Klose <doko@net.local>
Subject: c++/10891: code using dynamic_cast causes segfaults when -fno-rtti is used
Date: Tue, 20 May 2003 22:06:00 -0000	[thread overview]
Message-ID: <> (raw)

>Number:         10891
>Category:       c++
>Synopsis:       code using dynamic_cast causes segfaults when -fno-rtti is used
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 20 22:06:00 UTC 2003
>Originator:     Sean 'Shaleh' Perry <>
>Release:        3.3 (Debian) (Debian testing/unstable)
The Debian Project
System: Debian GNU/Linux (unstable)
Architecture: i686
 [ Reported to the Debian BTS as report #188943.
   Please CC on replies.
   Log of report can be found at ]

3.2.3 / 3.3

Now obviously, dynamic_cast requires rtti so using -fno-rtti is silly.
I ran into this on a C++ project where we had been using -fno-rtti because rtti
was not used.  A recent commit added dynamic_cast code and started segfaulting.
It was believed that the dynamic_cast was at fault and this caused some finger
pointing.  Then the no-rtti was noticed.

The compiler should give a warning (or perhaps even an error) if code requiring
rtti is used while the -fno-rtti option is in effect.

#include <iostream>

class EventHandler {
  virtual ~EventHandler(void) {}

  virtual void thisEvent(void) {}
  virtual void thatEvent(void) {}

class MyMenu: public EventHandler {
  virtual void thisEvent(void) { std::cout << "this Menu handler\n"; }
  virtual void thatEvent(void) { std::cout << "that Menu handler\n"; }

class OtherThing: public EventHandler {
  virtual void thisEvent(void) { std::cout << "this OtherThing handler\n"; }
  virtual void thatEvent(void) { std::cout << "that OtherThing handler\n"; }

void do_event(EventHandler* handler) {
  if (dynamic_cast<MyMenu*>(handler)) {
    // also call thatHandler for menus


int main(int argc, char* argv[]) {
  MyMenu menu;
  OtherThing thing;





                 reply	other threads:[~2003-05-20 22:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \
    --to=doko@net.local \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).