xref: /aosp_15_r20/external/clang/test/SemaCXX/no-exceptions.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // Various tests for -fno-exceptions
4*67e74705SXin Li 
5*67e74705SXin Li typedef __SIZE_TYPE__ size_t;
6*67e74705SXin Li 
7*67e74705SXin Li namespace test0 {
8*67e74705SXin Li   // rdar://problem/7878149
9*67e74705SXin Li   class Foo {
10*67e74705SXin Li   public:
11*67e74705SXin Li     void* operator new(size_t x);
12*67e74705SXin Li   private:
13*67e74705SXin Li     void operator delete(void *x);
14*67e74705SXin Li   };
15*67e74705SXin Li 
test()16*67e74705SXin Li   void test() {
17*67e74705SXin Li     // Under -fexceptions, this does access control for the associated
18*67e74705SXin Li     // 'operator delete'.
19*67e74705SXin Li     (void) new Foo();
20*67e74705SXin Li   }
21*67e74705SXin Li }
22*67e74705SXin Li 
23*67e74705SXin Li namespace test1 {
f()24*67e74705SXin Li void f() {
25*67e74705SXin Li   throw; // expected-error {{cannot use 'throw' with exceptions disabled}}
26*67e74705SXin Li }
27*67e74705SXin Li 
g()28*67e74705SXin Li void g() {
29*67e74705SXin Li   try { // expected-error {{cannot use 'try' with exceptions disabled}}
30*67e74705SXin Li     f();
31*67e74705SXin Li   } catch (...) {
32*67e74705SXin Li   }
33*67e74705SXin Li }
34*67e74705SXin Li 
35*67e74705SXin Li }
36