Debian Codegraph @

clang/test/Sema/assume.c

raw
1 // RUN: %clang_cc1 -std=c23 %s -verify
2
3 // Validate that the attribute works in C.
4 static_assert(!__has_c_attribute(assume));
5 static_assert(__has_c_attribute(clang::assume));
6 static_assert(__has_attribute(assume));
7
8 void test(int n) {
9 // Smoke test.
10 __attribute__((assume(true)));
11 [[clang::assume(true)]];
12
13 // Test diagnostics
14 __attribute__((assume)); // expected-error {{'assume' attribute takes one argument}}
15 __attribute__((assume())); // expected-error {{expected expression}}
16 [[clang::assume]]; // expected-error {{'assume' attribute takes one argument}}
17 [[clang::assume()]]; // expected-error {{expected expression}}
18
19 __attribute__((assume(n++))); // expected-warning {{assumption is ignored because it contains (potential) side-effects}}
20 [[clang::assume(n++)]]; // expected-warning {{assumption is ignored because it contains (potential) side-effects}}
21
22 [[clang::assume(true)]] int x; // expected-error {{'clang::assume' attribute cannot be applied to a declaration}}
23 __attribute__((assume(true))) int y; // expected-error {{'assume' attribute cannot be applied to a declaration}}
24 }
25