2013-12-06 05:54:49 +08:00
|
|
|
//===--------------------- catch_const_pointer_nullptr.cpp ----------------===//
|
2012-02-02 06:27:24 +08:00
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-02-02 06:27:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-04-17 22:29:15 +08:00
|
|
|
// UNSUPPORTED: no-exceptions
|
2016-05-31 20:01:32 +08:00
|
|
|
|
2012-02-02 06:27:24 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
2016-06-16 03:07:19 +08:00
|
|
|
// Clang emits warnings about exceptions of type 'Child' being caught by
|
|
|
|
// an earlier handler of type 'Base'. Congrats clang, you've just
|
|
|
|
// diagnosed the behavior under test.
|
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma clang diagnostic ignored "-Wexceptions"
|
|
|
|
#endif
|
|
|
|
|
2012-02-02 06:27:24 +08:00
|
|
|
#if __has_feature(cxx_nullptr)
|
|
|
|
|
|
|
|
struct A {};
|
|
|
|
|
|
|
|
void test1()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw nullptr;
|
|
|
|
assert(false);
|
|
|
|
}
|
2016-07-20 04:19:37 +08:00
|
|
|
catch (A* p)
|
2012-02-02 06:27:24 +08:00
|
|
|
{
|
2016-07-20 04:19:37 +08:00
|
|
|
assert(!p);
|
2012-02-02 06:27:24 +08:00
|
|
|
}
|
|
|
|
catch (const A*)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test2()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw nullptr;
|
|
|
|
assert(false);
|
|
|
|
}
|
2016-07-20 04:19:37 +08:00
|
|
|
catch (const A* p)
|
2012-02-02 06:27:24 +08:00
|
|
|
{
|
2016-07-20 04:19:37 +08:00
|
|
|
assert(!p);
|
2012-02-02 06:27:24 +08:00
|
|
|
}
|
|
|
|
catch (A*)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test3()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw nullptr;
|
|
|
|
assert(false);
|
|
|
|
}
|
2016-07-20 04:19:37 +08:00
|
|
|
catch (const A* const p)
|
2012-02-02 06:27:24 +08:00
|
|
|
{
|
2016-07-20 04:19:37 +08:00
|
|
|
assert(!p);
|
2012-02-02 06:27:24 +08:00
|
|
|
}
|
|
|
|
catch (A*)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test4()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw nullptr;
|
|
|
|
assert(false);
|
|
|
|
}
|
2016-07-20 04:19:37 +08:00
|
|
|
catch (A* p)
|
2012-02-02 06:27:24 +08:00
|
|
|
{
|
2016-07-20 04:19:37 +08:00
|
|
|
assert(!p);
|
2012-02-02 06:27:24 +08:00
|
|
|
}
|
2013-12-04 13:39:55 +08:00
|
|
|
catch (const A* const)
|
2012-02-02 06:27:24 +08:00
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test5()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw nullptr;
|
|
|
|
assert(false);
|
|
|
|
}
|
2016-07-20 04:19:37 +08:00
|
|
|
catch (A const* p)
|
2012-02-02 06:27:24 +08:00
|
|
|
{
|
2016-07-20 04:19:37 +08:00
|
|
|
assert(!p);
|
2012-02-02 06:27:24 +08:00
|
|
|
}
|
|
|
|
catch (A*)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test6()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw nullptr;
|
|
|
|
assert(false);
|
|
|
|
}
|
2016-07-20 04:19:37 +08:00
|
|
|
catch (A* p)
|
2012-02-02 06:27:24 +08:00
|
|
|
{
|
2016-07-20 04:19:37 +08:00
|
|
|
assert(!p);
|
2012-02-02 06:27:24 +08:00
|
|
|
}
|
|
|
|
catch (A const*)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void test1() {}
|
|
|
|
void test2() {}
|
|
|
|
void test3() {}
|
|
|
|
void test4() {}
|
|
|
|
void test5() {}
|
|
|
|
void test6() {}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-10-09 01:36:33 +08:00
|
|
|
int main(int, char**) {
|
2012-02-02 06:27:24 +08:00
|
|
|
test1();
|
|
|
|
test2();
|
|
|
|
test3();
|
|
|
|
test4();
|
|
|
|
test5();
|
|
|
|
test6();
|
2020-10-09 01:36:33 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-02-02 06:27:24 +08:00
|
|
|
}
|