[Bug c++/25466] typeid expression fails to throw bad_typeid according to 5.2.8p2

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sat Dec 17 21:52:00 GMT 2005



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



More information about the Gcc-bugs mailing list