| 1 |
// P1774R8 - Portable assumptions |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
[[__assume__ (true)]] void f1 (); // { dg-error "'assume' attribute ignored" } |
| 5 |
typedef int intx [[__assume__ (true)]]; // { dg-error "'assume' attribute ignored" } |
| 6 |
[[__assume__ (true)]]; // { dg-warning "attribute ignored" } |
| 7 |
[[gnu::assume (true)]] void f1a (); // { dg-error "'assume' attribute ignored" } |
| 8 |
typedef int inty [[gnu::__assume__ (true)]]; // { dg-error "'assume' attribute ignored" } |
| 9 |
[[__gnu__::assume (true)]]; // { dg-warning "attribute ignored" } |
| 10 |
__attribute__((assume (true))) void f1b (); // { dg-error "'assume' attribute ignored" } |
| 11 |
typedef int intz __attribute__((assume (true)));// { dg-error "'assume' attribute ignored" } |
| 12 |
|
| 13 |
void |
| 14 |
foo () |
| 15 |
{ |
| 16 |
int i; |
| 17 |
[[__assume__]]; // { dg-error "wrong number of arguments specified for 'assume' attribute" } |
| 18 |
// { dg-message "expected 1, found 0" "" { target *-*-* } .-1 } |
| 19 |
[[__assume__ ()]]; // { dg-error "parentheses must be omitted if 'assume' attribute argument list is empty" } |
| 20 |
// { dg-error "wrong number of arguments specified for 'assume' attribute" "" { target *-*-* } .-1 } |
| 21 |
// { dg-message "expected 1, found 0" "" { target *-*-* } .-2 } |
| 22 |
[[__assume__ (true, true)]]; // { dg-error "wrong number of arguments specified for 'assume' attribute" } |
| 23 |
// { dg-message "expected 1, found 2" "" { target *-*-* } .-1 } |
| 24 |
[[__assume__ (true)]] i = 1; // { dg-warning "'assume' attribute not followed by ';'" } |
| 25 |
[[__assume__ (throw 1)]]; // { dg-error "expected primary-expression before 'throw'" } |
| 26 |
[[__assume__ (i = 1)]]; // { dg-error "expected '\\\)' before '=' token" } |
| 27 |
[[gnu::assume]]; // { dg-error "wrong number of arguments specified for 'assume' attribute" } |
| 28 |
// { dg-message "expected 1, found 0" "" { target *-*-* } .-1 } |
| 29 |
[[gnu::assume ()]]; // { dg-error "parentheses must be omitted if 'assume' attribute argument list is empty" } |
| 30 |
// { dg-error "wrong number of arguments specified for 'assume' attribute" "" { target *-*-* } .-1 } |
| 31 |
// { dg-message "expected 1, found 0" "" { target *-*-* } .-2 } |
| 32 |
[[gnu::assume (true, true)]]; // { dg-error "wrong number of arguments specified for 'assume' attribute" } |
| 33 |
// { dg-message "expected 1, found 2" "" { target *-*-* } .-1 } |
| 34 |
[[gnu::assume (true)]] i = 1; // { dg-warning "'assume' attribute not followed by ';'" } |
| 35 |
[[gnu::assume (throw 1)]]; // { dg-error "expected primary-expression before 'throw'" } |
| 36 |
[[gnu::assume (i = 1)]]; // { dg-error "expected '\\\)' before '=' token" } |
| 37 |
__attribute__((assume)); // { dg-error "wrong number of arguments specified for 'assume' attribute" } |
| 38 |
// { dg-message "expected 1, found 0" "" { target *-*-* } .-1 } |
| 39 |
__attribute__((assume ())); // { dg-error "wrong number of arguments specified for 'assume' attribute" } |
| 40 |
// { dg-message "expected 1, found 0" "" { target *-*-* } .-1 } |
| 41 |
__attribute__((assume (true, true))); // { dg-error "wrong number of arguments specified for 'assume' attribute" } |
| 42 |
// { dg-message "expected 1, found 2" "" { target *-*-* } .-1 } |
| 43 |
__attribute__((assume (true))) i = 1; // { dg-warning "'assume' attribute not followed by ';'" } |
| 44 |
__attribute__((assume (throw 1))); // { dg-error "expected primary-expression before 'throw'" } |
| 45 |
__attribute__((assume (i = 1))); // { dg-error "expected '\\\)' before '=' token" } |
| 46 |
} |
| 47 |
|
| 48 |
constexpr int |
| 49 |
f2 (int x) |
| 50 |
{ |
| 51 |
#if __cpp_constexpr >= 201304L |
| 52 |
[[__assume__ (x == 42)]]; // { dg-error "failed 'assume' attribute assumption" "" { target c++14 } } |
| 53 |
#endif |
| 54 |
return x; |
| 55 |
} |
| 56 |
|
| 57 |
constexpr int |
| 58 |
f2a (int x) |
| 59 |
{ |
| 60 |
#if __cpp_constexpr >= 201304L |
| 61 |
[[gnu::__assume__ (x == 42)]]; // { dg-error "failed 'assume' attribute assumption" "" { target c++14 } } |
| 62 |
#endif |
| 63 |
return x; |
| 64 |
} |
| 65 |
|
| 66 |
constexpr int |
| 67 |
f2b (int x) |
| 68 |
{ |
| 69 |
#if __cpp_constexpr >= 201304L |
| 70 |
__attribute__((__assume__ (x == 42)));// { dg-error "failed 'assume' attribute assumption" "" { target c++14 } } |
| 71 |
#endif |
| 72 |
return x; |
| 73 |
} |
| 74 |
|
| 75 |
constexpr int a = f2 (44); |
| 76 |
constexpr int aa = f2a (44); |
| 77 |
constexpr int ab = f2b (44); |
| 78 |
|
| 79 |
int |
| 80 |
f3 (int x) |
| 81 |
{ |
| 82 |
__asm ("" : "+r" (x)); |
| 83 |
return x; |
| 84 |
} |
| 85 |
|
| 86 |
constexpr int |
| 87 |
f4 (int x) |
| 88 |
{ |
| 89 |
#if __cpp_constexpr >= 201304L |
| 90 |
[[__assume__ (f3 (42) == 42)]]; |
| 91 |
#endif |
| 92 |
return x; |
| 93 |
} |
| 94 |
|
| 95 |
constexpr int |
| 96 |
f4a (int x) |
| 97 |
{ |
| 98 |
#if __cpp_constexpr >= 201304L |
| 99 |
[[gnu::assume (f3 (42) == 42)]]; |
| 100 |
#endif |
| 101 |
return x; |
| 102 |
} |
| 103 |
|
| 104 |
constexpr int |
| 105 |
f4b (int x) |
| 106 |
{ |
| 107 |
#if __cpp_constexpr >= 201304L |
| 108 |
__attribute__((assume (f3 (42) == 42))); |
| 109 |
#endif |
| 110 |
return x; |
| 111 |
} |
| 112 |
|
| 113 |
static_assert (f4 (42) == 42, ""); |
| 114 |
static_assert (f4a (42) == 42, ""); |
| 115 |
static_assert (f4b (42) == 42, ""); |
| 116 |
|
| 117 |
struct S {}; |
| 118 |
|
| 119 |
int |
| 120 |
f5 () |
| 121 |
{ |
| 122 |
S s; |
| 123 |
[[gnu::assume (s)]]; // { dg-error "could not convert 's' from 'S' to 'bool'" } |
| 124 |
return 0; |
| 125 |
} |
| 126 |
|
| 127 |
template <typename T> |
| 128 |
int |
| 129 |
f6 () |
| 130 |
{ |
| 131 |
T t; |
| 132 |
__attribute__((assume (t))); // { dg-error "could not convert 't' from 'S' to 'bool'" } |
| 133 |
return 0; |
| 134 |
} |
| 135 |
|
| 136 |
int z = f6 <S> (); |