public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hhinnant at apple dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/25466]  New: typeid expression fails to throw bad_typeid according to 5.2.8p2
Date: Sat, 17 Dec 2005 21:35:00 -0000	[thread overview]
Message-ID: <bug-25466-11686@http.gcc.gnu.org/bugzilla/> (raw)

5.2.8p2 says that if a typeid expression refers to a polymorphic type and the
expression is formed by dereferencing a null pointer that a bad_typeid should
be thrown.

#include <iostream>
#include <typeinfo>

template <class T>
bool is_polymorphic() {
   bool result(false);
   typeid( (result=true), *(T*)0);
   return result;
}

struct non_polymorphic {};
struct polymorphic { virtual ~polymorphic() {} };


int main() {
   std::cout << is_polymorphic<int>() << '\n';
   std::cout << is_polymorphic<non_polymorphic>() << '\n';
   try
   {
      std::cout << is_polymorphic<polymorphic>() << '\n';              //3
      std::cout << "Fail, should have thrown bad_typeid\n";
   }
   catch (std::bad_typeid&)
   {
      std::cout << "Pass\n";
   }
   catch (...)
   {
      std::cout << "Fail, bad_typeid not caught\n";
   }
}

Expected output:

0
0
Pass

Output received with gcc 4.0.1

0
0
1
Fail, should have thrown bad_typeid


-- 
           Summary: typeid expression fails to throw bad_typeid according to
                    5.2.8p2
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hhinnant at apple dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25466


             reply	other threads:[~2005-12-17 21:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-17 21:35 hhinnant at apple dot com [this message]
2005-12-17 21:44 ` [Bug c++/25466] " pinskia at gcc dot gnu dot org
2005-12-17 21:52 ` pinskia at gcc dot gnu dot org
2005-12-17 21:55 ` pinskia at gcc dot gnu dot org
2005-12-17 22:01 ` hhinnant at apple dot com

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=bug-25466-11686@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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).