blob: 2d4a957f1276b23c908015c80f035579a89b6409 [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
3// expected-no-diagnostics
4
5class MayExist {
6private:
7 typedef int Type;
8};
9
10void test_if_exists_stmts() {
11 int b = 0;
12 __if_exists(MayExist::Type) {
13 b++;
14 b++;
15 }
16 __if_exists(MayExist::Type_not) {
17 this will not compile.
18 }
19 __if_not_exists(MayExist::Type) {
20 this will not compile.
21 }
22 __if_not_exists(MayExist::Type_not) {
23 b++;
24 b++;
25 }
26}
27
Reid Kleckner6be648f2014-06-25 00:10:50 +000028int if_exists_creates_no_scope() {
29 __if_exists(MayExist::Type) {
30 int x; // 'x' is declared in the parent scope.
31 }
32 __if_not_exists(MayExist::Type_not) {
33 x++;
34 }
35 return x;
36}
37
Reid Kleckner27e14732014-06-25 00:08:10 +000038__if_exists(MayExist::Type) {
39 int var23;
40}
41
42__if_exists(MayExist::Type_not) {
43 this will not compile.
44}
45
46__if_not_exists(MayExist::Type) {
47 this will not compile.
48}
49
50__if_not_exists(MayExist::Type_not) {
51 int var244;
52}
53
54void test_if_exists_init_list() {
55
56 int array1[] = {
57 0,
58 __if_exists(MayExist::Type) {2, }
59 3
60 };
61
62 int array2[] = {
63 0,
64 __if_exists(MayExist::Type_not) { this will not compile }
65 3
66 };
67
68 int array3[] = {
69 0,
70 __if_not_exists(MayExist::Type_not) {2, }
71 3
72 };
73
74 int array4[] = {
75 0,
76 __if_not_exists(MayExist::Type) { this will not compile }
77 3
78 };
79
80}
81
82
83class IfExistsClassScope {
84 __if_exists(MayExist::Type) {
85 // __if_exists, __if_not_exists can nest
86 __if_not_exists(MayExist::Type_not) {
87 int var123;
88 }
89 int var23;
90 }
91
92 __if_exists(MayExist::Type_not) {
93 this will not compile.
94 }
95
96 __if_not_exists(MayExist::Type) {
97 this will not compile.
98 }
99
100 __if_not_exists(MayExist::Type_not) {
101 int var244;
102 }
103};