| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s |
| 2 |
|
| 3 |
// Various tests for -fno-exceptions |
| 4 |
|
| 5 |
typedef __SIZE_TYPE__ size_t; |
| 6 |
|
| 7 |
namespace test0 { |
| 8 |
class Foo { |
| 9 |
public: |
| 10 |
void* operator new(size_t x); |
| 11 |
private: |
| 12 |
void operator delete(void *x); |
| 13 |
}; |
| 14 |
|
| 15 |
void test() { |
| 16 |
// Under -fexceptions, this does access control for the associated |
| 17 |
// 'operator delete'. |
| 18 |
(void) new Foo(); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
namespace test1 { |
| 23 |
void f() { |
| 24 |
throw; // expected-error {{cannot use 'throw' with exceptions disabled}} |
| 25 |
} |
| 26 |
|
| 27 |
void g() { |
| 28 |
try { // expected-error {{cannot use 'try' with exceptions disabled}} |
| 29 |
f(); |
| 30 |
} catch (...) { |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
namespace test2 { |
| 36 |
template <auto enable> void foo(auto &&Fnc) { |
| 37 |
if constexpr (enable) |
| 38 |
try { |
| 39 |
Fnc(); |
| 40 |
} catch (...) { |
| 41 |
} |
| 42 |
else |
| 43 |
Fnc(); |
| 44 |
} |
| 45 |
|
| 46 |
void bar1() { |
| 47 |
foo<false>([] {}); |
| 48 |
} |
| 49 |
|
| 50 |
template <typename T> void foo() { |
| 51 |
try { // expected-error {{cannot use 'try' with exceptions disabled}} |
| 52 |
} catch (...) { |
| 53 |
} |
| 54 |
throw 1; // expected-error {{cannot use 'throw' with exceptions disabled}} |
| 55 |
} |
| 56 |
void bar2() { foo<int>(); } // expected-note {{in instantiation of function template specialization 'test2::foo<int>' requested here}} |
| 57 |
} |