58 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s2 3// Various tests for -fno-exceptions4 5typedef __SIZE_TYPE__ size_t;6 7namespace 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 associated17 // 'operator delete'.18 (void) new Foo();19 }20}21 22namespace test1 {23void f() {24 throw; // expected-error {{cannot use 'throw' with exceptions disabled}}25}26 27void g() {28 try { // expected-error {{cannot use 'try' with exceptions disabled}}29 f();30 } catch (...) {31 }32}33}34 35namespace test2 {36template <auto enable> void foo(auto &&Fnc) {37 if constexpr (enable)38 try {39 Fnc();40 } catch (...) {41 }42 else43 Fnc();44}45 46void bar1() {47 foo<false>([] {});48}49 50template <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}56void bar2() { foo<int>(); } // expected-note {{in instantiation of function template specialization 'test2::foo<int>' requested here}}57}58