annotate clang/test/Parser/ms-if-exists.cpp @ 223:5f17cb93ff66 llvm-original

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