blob: 79cc571a357ff9a408b9e7931b64017f9c4c4729 [file] [log] [blame]
Reid Kleckner27e14732014-06-25 00:08:10 +00001// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wmicrosoft -verify -fms-extensions
2
Reid Kleckner27e14732014-06-25 00:08:10 +00003class MayExist {
4private:
5 typedef int Type;
6};
7
8void 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
Reid Kleckner6be648f2014-06-25 00:10:50 +000026int 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
Reid Kleckner27e14732014-06-25 00:08:10 +000036__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
52void 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
81class 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};
Reid Kleckner6d8d22a2014-06-25 00:28:35 +0000102
103void 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
112void 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}