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; 5+ 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] 5+ messages in thread

* [Bug c++/25466] typeid expression fails to throw bad_typeid according to 5.2.8p2
  2005-12-17 21:35 [Bug libstdc++/25466] New: typeid expression fails to throw bad_typeid according to 5.2.8p2 hhinnant at apple dot com
@ 2005-12-17 21:44 ` pinskia at gcc dot gnu dot org
  2005-12-17 21:52 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-12-17 21:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2005-12-17 21:44 -------
This is a front-end issue:
  <<cleanup_point <<< Unknown tree: expr_stmt  (void) (struct type_info *)
*(((void) (result = 1);  *0B;)._vptr.polymorphic + -4B) >>>>>;

Confirmed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|libstdc++                   |c++
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2005-12-17 21:44:06
               date|                            |


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


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

* [Bug c++/25466] typeid expression fails to throw bad_typeid according to 5.2.8p2
  2005-12-17 21:35 [Bug libstdc++/25466] New: typeid expression fails to throw bad_typeid according to 5.2.8p2 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
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-12-17 21:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2005-12-17 21:52 -------
So for the following:
#include <iostream>
#include <typeinfo>

const std::type_info *a;

template <class T>
bool is_polymorphic() {
   bool result(false);
   const std::type_info &a1 = typeid( (result=true), *(T*)0);
   a = &a1;
   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";
   }
}

Should Pass and not just seg fault (if I am reading this correctly).


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |2.95.3 4.0.0 3.4.0 3.3.3


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


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

* [Bug c++/25466] typeid expression fails to throw bad_typeid according to 5.2.8p2
  2005-12-17 21:35 [Bug libstdc++/25466] New: typeid expression fails to throw bad_typeid according to 5.2.8p2 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
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-12-17 21:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2005-12-17 21:55 -------
*** Bug 25467 has been marked as a duplicate of this bug. ***


-- 


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


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

* [Bug c++/25466] typeid expression fails to throw bad_typeid according to 5.2.8p2
  2005-12-17 21:35 [Bug libstdc++/25466] New: typeid expression fails to throw bad_typeid according to 5.2.8p2 hhinnant at apple dot com
                   ` (2 preceding siblings ...)
  2005-12-17 21:55 ` pinskia at gcc dot gnu dot org
@ 2005-12-17 22:01 ` hhinnant at apple dot com
  3 siblings, 0 replies; 5+ messages in thread
From: hhinnant at apple dot com @ 2005-12-17 22:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hhinnant at apple dot com  2005-12-17 22:01 -------
Agreed, (that's brutal ;-) ).

Sorry about the duplicate.  My clumsy fingers hit refresh on my browser and
that generated the duplicate.


-- 


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


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

end of thread, other threads:[~2005-12-17 22:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-17 21:35 [Bug libstdc++/25466] New: typeid expression fails to throw bad_typeid according to 5.2.8p2 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).