| 1 |
#include <type_traits> |
| 2 |
|
| 3 |
/* Use std::remove_pointer_t<T> here in order to make `int *` fail when using |
| 4 |
the INVALID_PARAMETERS block. Pointers of two different types are allowed |
| 5 |
in __builtin_speculation_safe_value, it's one argument of a pointer and |
| 6 |
another argument that is not a pointer that give errors. */ |
| 7 |
#define SPECULATION_SFINAES \ |
| 8 |
SFINAE_TYPE_CHECK ((std::declval<T> (), std::declval<T> ()), \ |
| 9 |
(std::declval<T> ()), \ |
| 10 |
(std::declval<std::remove_pointer_t<T>> (), std::declval<T *> ())) |
| 11 |
|
| 12 |
SPECULATION_SFINAES |
| 13 |
|
| 14 |
class X{}; |
| 15 |
class Large { public: int arr[10]; }; |
| 16 |
class Incomplete; |
| 17 |
|
| 18 |
/* Using `true_def` in order to account for the fact that if this target |
| 19 |
* doesn't support __builtin_speculation_safe_value at all everything fails to |
| 20 |
* substitute. */ |
| 21 |
#define SPECULATION_ASSERTS \ |
| 22 |
MAKE_SPECULATION_ASSERT (int, true_def) \ |
| 23 |
MAKE_SPECULATION_ASSERT (float, false) \ |
| 24 |
MAKE_SPECULATION_ASSERT (X, false) \ |
| 25 |
MAKE_SPECULATION_ASSERT (Large, false) \ |
| 26 |
MAKE_SPECULATION_ASSERT (Incomplete, false) \ |
| 27 |
MAKE_SPECULATION_ASSERT (int *, true_def) \ |
| 28 |
MAKE_SPECULATION_ASSERT (long, true_def) |
| 29 |
|
| 30 |
int main() { |
| 31 |
SPECULATION_ASSERTS |
| 32 |
return 0; |
| 33 |
} |