xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/ms-if-exists.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
2*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
3*0a6a1f1dSLionel Sambuc 
4*0a6a1f1dSLionel Sambuc struct Type {
5*0a6a1f1dSLionel Sambuc };
6*0a6a1f1dSLionel Sambuc 
test_if_exists_stmts()7*0a6a1f1dSLionel Sambuc void test_if_exists_stmts() {
8*0a6a1f1dSLionel Sambuc   int b = 0;
9*0a6a1f1dSLionel Sambuc   __if_exists(Type) {
10*0a6a1f1dSLionel Sambuc     b++;
11*0a6a1f1dSLionel Sambuc     b++;
12*0a6a1f1dSLionel Sambuc   }
13*0a6a1f1dSLionel Sambuc   __if_exists(Type_not) {
14*0a6a1f1dSLionel Sambuc     this will not compile.
15*0a6a1f1dSLionel Sambuc   }
16*0a6a1f1dSLionel Sambuc   __if_not_exists(Type) {
17*0a6a1f1dSLionel Sambuc     this will not compile.
18*0a6a1f1dSLionel Sambuc   }
19*0a6a1f1dSLionel Sambuc   __if_not_exists(Type_not) {
20*0a6a1f1dSLionel Sambuc     b++;
21*0a6a1f1dSLionel Sambuc     b++;
22*0a6a1f1dSLionel Sambuc   }
23*0a6a1f1dSLionel Sambuc }
24*0a6a1f1dSLionel Sambuc 
if_exists_creates_no_scope()25*0a6a1f1dSLionel Sambuc int if_exists_creates_no_scope() {
26*0a6a1f1dSLionel Sambuc   __if_exists(Type) {
27*0a6a1f1dSLionel Sambuc     int x;  // 'x' is declared in the parent scope.
28*0a6a1f1dSLionel Sambuc   }
29*0a6a1f1dSLionel Sambuc   __if_not_exists(Type_not) {
30*0a6a1f1dSLionel Sambuc     x++;
31*0a6a1f1dSLionel Sambuc   }
32*0a6a1f1dSLionel Sambuc   return x;
33*0a6a1f1dSLionel Sambuc }
34*0a6a1f1dSLionel Sambuc 
__if_exists(Type)35*0a6a1f1dSLionel Sambuc __if_exists(Type) {
36*0a6a1f1dSLionel Sambuc   int var23;
37*0a6a1f1dSLionel Sambuc }
38*0a6a1f1dSLionel Sambuc 
__if_exists(Type_not)39*0a6a1f1dSLionel Sambuc __if_exists(Type_not) {
40*0a6a1f1dSLionel Sambuc   this will not compile.
41*0a6a1f1dSLionel Sambuc }
42*0a6a1f1dSLionel Sambuc 
__if_not_exists(Type)43*0a6a1f1dSLionel Sambuc __if_not_exists(Type) {
44*0a6a1f1dSLionel Sambuc   this will not compile.
45*0a6a1f1dSLionel Sambuc }
46*0a6a1f1dSLionel Sambuc 
__if_not_exists(Type_not)47*0a6a1f1dSLionel Sambuc __if_not_exists(Type_not) {
48*0a6a1f1dSLionel Sambuc   int var244;
49*0a6a1f1dSLionel Sambuc }
50*0a6a1f1dSLionel Sambuc 
test_if_exists_init_list()51*0a6a1f1dSLionel Sambuc void test_if_exists_init_list() {
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc   int array1[] = {
54*0a6a1f1dSLionel Sambuc     0,
55*0a6a1f1dSLionel Sambuc     __if_exists(Type) {2, }
56*0a6a1f1dSLionel Sambuc     3
57*0a6a1f1dSLionel Sambuc   };
58*0a6a1f1dSLionel Sambuc 
59*0a6a1f1dSLionel Sambuc   int array2[] = {
60*0a6a1f1dSLionel Sambuc     0,
61*0a6a1f1dSLionel Sambuc     __if_exists(Type_not) { this will not compile }
62*0a6a1f1dSLionel Sambuc     3
63*0a6a1f1dSLionel Sambuc   };
64*0a6a1f1dSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc   int array3[] = {
66*0a6a1f1dSLionel Sambuc     0,
67*0a6a1f1dSLionel Sambuc     __if_not_exists(Type_not) {2, }
68*0a6a1f1dSLionel Sambuc     3
69*0a6a1f1dSLionel Sambuc   };
70*0a6a1f1dSLionel Sambuc 
71*0a6a1f1dSLionel Sambuc   int array4[] = {
72*0a6a1f1dSLionel Sambuc     0,
73*0a6a1f1dSLionel Sambuc     __if_not_exists(Type) { this will not compile }
74*0a6a1f1dSLionel Sambuc     3
75*0a6a1f1dSLionel Sambuc   };
76*0a6a1f1dSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc }
78*0a6a1f1dSLionel Sambuc 
79*0a6a1f1dSLionel Sambuc 
test_nested_if_exists()80*0a6a1f1dSLionel Sambuc void test_nested_if_exists() {
81*0a6a1f1dSLionel Sambuc   __if_exists(Type) {
82*0a6a1f1dSLionel Sambuc     int x = 42;
83*0a6a1f1dSLionel Sambuc     __if_not_exists(Type_not) {
84*0a6a1f1dSLionel Sambuc       x++;
85*0a6a1f1dSLionel Sambuc     }
86*0a6a1f1dSLionel Sambuc   }
87*0a6a1f1dSLionel Sambuc }
88