xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/cxx-stmt.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
f1()3*f4a2713aSLionel Sambuc void f1()
4*f4a2713aSLionel Sambuc {
5*f4a2713aSLionel Sambuc   try {
6*f4a2713aSLionel Sambuc     ;
7*f4a2713aSLionel Sambuc   } catch(int i) {
8*f4a2713aSLionel Sambuc     ;
9*f4a2713aSLionel Sambuc   } catch(...) {
10*f4a2713aSLionel Sambuc   }
11*f4a2713aSLionel Sambuc }
12*f4a2713aSLionel Sambuc 
f2()13*f4a2713aSLionel Sambuc void f2()
14*f4a2713aSLionel Sambuc {
15*f4a2713aSLionel Sambuc   try; // expected-error {{expected '{'}}
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc   try {}
18*f4a2713aSLionel Sambuc   catch; // expected-error {{expected '('}}
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc   try {}
21*f4a2713aSLionel Sambuc   catch (...); // expected-error {{expected '{'}}
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc   try {}
24*f4a2713aSLionel Sambuc   catch {} // expected-error {{expected '('}}
25*f4a2713aSLionel Sambuc }
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc void f3() try {
28*f4a2713aSLionel Sambuc } catch(...) {
29*f4a2713aSLionel Sambuc }
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc struct A {
32*f4a2713aSLionel Sambuc   int i;
33*f4a2713aSLionel Sambuc   A(int);
34*f4a2713aSLionel Sambuc   A(char);
35*f4a2713aSLionel Sambuc   A() try : i(0) {} catch(...) {}
36*f4a2713aSLionel Sambuc   void f() try {} catch(...) {}
37*f4a2713aSLionel Sambuc   A(float) : i(0) try {} // expected-error {{expected '{' or ','}}
38*f4a2713aSLionel Sambuc };
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc A::A(char) : i(0) try {} // expected-error {{expected '{' or ','}}
41*f4a2713aSLionel Sambuc A::A(int j) try : i(j) {} catch(...) {}
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc // PR5740
46*f4a2713aSLionel Sambuc struct Type { };
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc enum { Type } Kind;
49*f4a2713aSLionel Sambuc void f4() {
50*f4a2713aSLionel Sambuc   int i = 0;
51*f4a2713aSLionel Sambuc   switch (Kind) {
52*f4a2713aSLionel Sambuc     case Type: i = 7; break;  // no error.
53*f4a2713aSLionel Sambuc   }
54*f4a2713aSLionel Sambuc }
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc // PR5500
57*f4a2713aSLionel Sambuc void f5() {
58*f4a2713aSLionel Sambuc   asm volatile ("":: :"memory");
59*f4a2713aSLionel Sambuc   asm volatile ("": ::"memory");
60*f4a2713aSLionel Sambuc }
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc int f6() {
63*f4a2713aSLionel Sambuc   int k, // expected-note {{change this ',' to a ';' to call 'f6'}}
64*f4a2713aSLionel Sambuc   f6(), // expected-error {{expected ';'}} expected-warning {{interpreted as a function declaration}} expected-note {{replace paren}}
65*f4a2713aSLionel Sambuc   int n = 0, // expected-error {{expected ';'}}
66*f4a2713aSLionel Sambuc   return f5(), // ok
67*f4a2713aSLionel Sambuc   int(n);
68*f4a2713aSLionel Sambuc }
69