public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/25466]  New: typeid expression fails to throw bad_typeid according to 5.2.8p2
@ 2005-12-17 21:35 hhinnant at apple dot com
  2005-12-17 21:44 ` [Bug c++/25466] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: hhinnant at apple dot com @ 2005-12-17 21:35 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2013-04-09 18:49 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-25466-4@http.gcc.gnu.org/bugzilla/>
2012-10-18 10:26 ` [Bug c++/25466] typeid expression fails to throw bad_typeid according to 5.2.8p2 paolo.carlini at oracle dot com
2012-10-31 21:55 ` paolo.carlini at oracle dot com
2012-11-01  1:01 ` paolo.carlini at oracle dot com
2012-11-01  7:12 ` daniel.kruegler at googlemail dot com
2012-11-01  8:40 ` paolo.carlini at oracle dot com
2012-11-01  9:11 ` daniel.kruegler at googlemail dot com
2012-11-01 11:53 ` paolo.carlini at oracle dot com
2013-03-27 10:13 ` paolo.carlini at oracle dot com
2013-04-03 17:21 ` jason at gcc dot gnu.org
2013-04-03 17:27 ` paolo.carlini at oracle dot com
2013-04-09 17:32 ` jason at gcc dot gnu.org
2013-04-09 17:34 ` paolo.carlini at oracle dot com
2013-04-09 18:49 ` jason at gcc dot gnu.org
2005-12-17 21:35 [Bug libstdc++/25466] New: " hhinnant at apple dot com
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

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