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