1 // RUN: %clang_cc1 %s -std=c++17 -fsyntax-only -verify
2 // RUN: %clang_cc1 %s -DPEDANTIC -pedantic -fsyntax-only -verify
7 [[likely
]] {} // expected-warning {{use of the 'likely' attribute is a C++20 extension}}
9 [[unlikely
]] {} // expected-warning {{use of the 'unlikely' attribute is a C++20 extension}}
14 [[likely
]]; // expected-warning {{conflicting attributes 'likely' are ignored}}
16 [[likely
]]; // expected-note {{conflicting attribute is here}}
21 [[unlikely
]]; // expected-warning {{conflicting attributes 'unlikely' are ignored}}
23 [[unlikely
]]; // expected-note {{conflicting attribute is here}}
73 [[unlikely
]] if (false) [[likely
]] {}
77 [[likely
]] int x
= 42; // expected-error {{'likely' attribute cannot be applied to a declaration}}
88 [[likely
]] case 2 : case 3 : {}
98 do { // expected-note {{to match this 'do'}}
100 [[unlikely
]] while (x
); // expected-error {{expected 'while' in do/while loop}}
118 // FIXME: allow the attribute on the label
119 [[unlikely
]] lbl
: // expected-error {{'unlikely' attribute cannot be applied to a declaration}}
120 [[likely
]] x
= x
+ 1;
125 void n() [[likely
]] // expected-error {{'likely' attribute cannot be applied to types}}
128 [[likely
]] {} // expected-error {{expected '{'}}
129 catch (...) [[likely
]] { // expected-error {{expected expression}}
135 // expected-warning@+2 {{attribute 'likely' has no effect when annotating an 'if constexpr' statement}}
136 // expected-note@+1 {{annotating the 'if constexpr' statement here}}
137 if constexpr (true) [[likely
]];
139 // expected-note@+1 {{annotating the 'if constexpr' statement here}}
140 if constexpr (true) {
141 // expected-warning@+1 {{attribute 'unlikely' has no effect when annotating an 'if constexpr' statement}}
144 // Annotating both branches with conflicting likelihoods generates no diagnostic regarding the conflict.
145 // expected-warning@+2 {{attribute 'likely' has no effect when annotating an 'if constexpr' statement}}
146 // expected-note@+1 2 {{annotating the 'if constexpr' statement here}}
147 if constexpr (true) [[likely
]] {
148 // expected-warning@+1 {{attribute 'likely' has no effect when annotating an 'if constexpr' statement}}
151 if (1) [[likely
, unlikely
]] { // expected-error {{'unlikely' and 'likely' attributes are not compatible}} \
152 // expected-note {{conflicting attribute is here}}
153 } else [[unlikely
]][[likely
]] { // expected-error {{'likely' and 'unlikely' attributes are not compatible}} \
154 // expected-note {{conflicting attribute is here}}
158 constexpr int constexpr_function() {
161 static_assert(constexpr_function() == 0);
163 constexpr double pow(double x
, long long n
) noexcept
{
164 if (n
> 0) [[likely
]]
165 return x
* pow(x
, n
- 1);
169 constexpr long long fact(long long n
) noexcept
{
170 if (n
> 1) [[likely
]]
171 return n
* fact(n
- 1);