[Bug libstdc++/25467] New: typeid expression fails to throw bad_typeid according to 5.2.8p2
hhinnant at apple dot com
gcc-bugzilla@gcc.gnu.org
Sat Dec 17 21:53:00 GMT 2005
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=25467
More information about the Gcc-bugs
mailing list