forked from OSchip/llvm-project
Fix PR17222 - catching derived classes from thrown null pointer. Adds tests, too
llvm-svn: 200864
This commit is contained in:
parent
c32818ac9b
commit
176be6fed5
|
@ -388,7 +388,8 @@ __pointer_type_info::can_catch(const __shim_type_info* thrown_type,
|
|||
thrown_class_type->has_unambiguous_public_base(&info, adjustedPtr, public_path);
|
||||
if (info.path_dst_ptr_to_static_ptr == public_path)
|
||||
{
|
||||
adjustedPtr = const_cast<void*>(info.dst_ptr_leading_to_static_ptr);
|
||||
if (adjustedPtr != NULL)
|
||||
adjustedPtr = const_cast<void*>(info.dst_ptr_leading_to_static_ptr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -33,7 +33,7 @@ void test2 ()
|
|||
{
|
||||
try
|
||||
{
|
||||
throw &a;
|
||||
throw &a;
|
||||
assert(false);
|
||||
}
|
||||
catch ( A* )
|
||||
|
@ -77,10 +77,85 @@ void test4 ()
|
|||
}
|
||||
}
|
||||
|
||||
struct base1 {int x;};
|
||||
struct base2 {int x;};
|
||||
struct derived : base1, base2 {};
|
||||
|
||||
void test5 ()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw (derived*)0;
|
||||
assert(false);
|
||||
}
|
||||
catch (base2 *p) {
|
||||
assert (p == 0);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert (false);
|
||||
}
|
||||
}
|
||||
|
||||
void test6 ()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw nullptr;
|
||||
assert(false);
|
||||
}
|
||||
catch (base2 *p) {
|
||||
assert (p == nullptr);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert (false);
|
||||
}
|
||||
}
|
||||
|
||||
void test7 ()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw (derived*)12;
|
||||
assert(false);
|
||||
}
|
||||
catch (base2 *p) {
|
||||
assert ((unsigned long)p == 12+sizeof(base1));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert (false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct vA {};
|
||||
struct vC : virtual public vA {};
|
||||
|
||||
void test8 ()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw (vC*)0;
|
||||
assert(false);
|
||||
}
|
||||
catch (vA *p) {
|
||||
assert(p == 0);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert (false);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
test6();
|
||||
test7();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue