attr-likelihood.cpp
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// RUN: %clang_cc1 %s -fsyntax-only -verify
// RUN: %clang_cc1 %s -DPEDANTIC -pedantic -fsyntax-only -verify
#if PEDANTIC
void g() {
if (true)
[[likely]] {} // expected-warning {{use of the 'likely' attribute is a C++20 extension}}
else
[[unlikely]] {} // expected-warning {{use of the 'unlikely' attribute is a C++20 extension}}
}
#else
void a() {
if (true)
[[likely]]; // expected-warning {{conflicting attributes 'likely' are ignored}}
else
[[likely]]; // expected-note {{conflicting attribute is here}}
}
void b() {
if (true)
[[unlikely]]; // expected-warning {{conflicting attributes 'unlikely' are ignored}}
else
[[unlikely]]; // expected-note {{conflicting attribute is here}}
}
void c() {
if (true)
[[likely]];
}
void d() {
if (true)
[[unlikely]];
}
void g() {
if (true)
[[likely]] {}
else
[[unlikely]] {}
}
void h() {
if (true)
[[likely]] {}
else {
}
}
void i() {
if (true)
[[unlikely]] {}
else {
}
}
void j() {
if (true) {
} else
[[likely]] {}
}
void k() {
if (true) {
} else
[[likely]] {}
}
void l() {
if (true)
[[likely]] {}
else
[[unlikely]] if (false) [[likely]] {}
}
void m() {
[[likely]] int x = 42; // expected-error {{'likely' attribute cannot be applied to a declaration}}
if (x)
[[unlikely]] {}
if (x) {
[[unlikely]];
}
switch (x) {
case 1:
[[likely]] {}
break;
[[likely]] case 2 : case 3 : {}
break;
}
do {
[[unlikely]];
} while (x);
do
[[unlikely]] {}
while (x);
do { // expected-note {{to match this 'do'}}
}
[[unlikely]] while (x); // expected-error {{expected 'while' in do/while loop}}
for (;;)
[[unlikely]] {}
for (;;) {
[[unlikely]];
}
while (x)
[[unlikely]] {}
while (x) {
[[unlikely]];
}
switch (x)
[[unlikely]] {}
if (x)
goto lbl;
// FIXME: allow the attribute on the label
[[unlikely]] lbl : // expected-error {{'unlikely' attribute cannot be applied to a declaration}}
[[likely]] x = x + 1;
[[likely]]++ x;
}
void n() [[likely]] // expected-error {{'likely' attribute cannot be applied to types}}
{
try
[[likely]] {} // expected-error {{expected '{'}}
catch (...) [[likely]] { // expected-error {{expected expression}}
}
}
#endif