1 | // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wmicrosoft -verify -fms-extensions |
2 | |
3 | class MayExist { |
4 | private: |
5 | typedef int Type; |
6 | }; |
7 | |
8 | void test_if_exists_stmts() { |
9 | int b = 0; |
10 | __if_exists(MayExist::Type) { |
11 | b++; |
12 | b++; |
13 | } |
14 | __if_exists(MayExist::Type_not) { |
15 | this will not compile. |
16 | } |
17 | __if_not_exists(MayExist::Type) { |
18 | this will not compile. |
19 | } |
20 | __if_not_exists(MayExist::Type_not) { |
21 | b++; |
22 | b++; |
23 | } |
24 | } |
25 | |
26 | int if_exists_creates_no_scope() { |
27 | __if_exists(MayExist::Type) { |
28 | int x; // 'x' is declared in the parent scope. |
29 | } |
30 | __if_not_exists(MayExist::Type_not) { |
31 | x++; |
32 | } |
33 | return x; |
34 | } |
35 | |
36 | __if_exists(MayExist::Type) { |
37 | int var23; |
38 | } |
39 | |
40 | __if_exists(MayExist::Type_not) { |
41 | this will not compile. |
42 | } |
43 | |
44 | __if_not_exists(MayExist::Type) { |
45 | this will not compile. |
46 | } |
47 | |
48 | __if_not_exists(MayExist::Type_not) { |
49 | int var244; |
50 | } |
51 | |
52 | void test_if_exists_init_list() { |
53 | |
54 | int array1[] = { |
55 | 0, |
56 | __if_exists(MayExist::Type) {2, } |
57 | 3 |
58 | }; |
59 | |
60 | int array2[] = { |
61 | 0, |
62 | __if_exists(MayExist::Type_not) { this will not compile } |
63 | 3 |
64 | }; |
65 | |
66 | int array3[] = { |
67 | 0, |
68 | __if_not_exists(MayExist::Type_not) {2, } |
69 | 3 |
70 | }; |
71 | |
72 | int array4[] = { |
73 | 0, |
74 | __if_not_exists(MayExist::Type) { this will not compile } |
75 | 3 |
76 | }; |
77 | |
78 | } |
79 | |
80 | |
81 | class IfExistsClassScope { |
82 | __if_exists(MayExist::Type) { |
83 | // __if_exists, __if_not_exists can nest |
84 | __if_not_exists(MayExist::Type_not) { |
85 | int var123; |
86 | } |
87 | int var23; |
88 | } |
89 | |
90 | __if_exists(MayExist::Type_not) { |
91 | this will not compile. |
92 | } |
93 | |
94 | __if_not_exists(MayExist::Type) { |
95 | this will not compile. |
96 | } |
97 | |
98 | __if_not_exists(MayExist::Type_not) { |
99 | int var244; |
100 | } |
101 | }; |
102 | |
103 | void test_nested_if_exists() { |
104 | __if_exists(MayExist::Type) { |
105 | int x = 42; |
106 | __if_not_exists(MayExist::Type_not) { |
107 | x++; |
108 | } |
109 | } |
110 | } |
111 | |
112 | void test_attribute_on_if_exists() { |
113 | [[clang::fallthrough]] // expected-error {{an attribute list cannot appear here}} |
114 | __if_exists(MayExist::Type) { |
115 | int x; |
116 | } |
117 | } |
118 | |