diff options
author | Florian Weimer <fweimer@redhat.com> | 2018-01-08 14:39:51 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2018-01-08 14:39:51 +0100 |
commit | dabd75b6a1180c2ca6a6f966f08cc00e8e72cce9 (patch) | |
tree | 0ef2deb94cfc78b49fd6448ba1267a77febb0ed3 /support | |
parent | c2e014cc33ef814a8f24fb7aabe1cee5265056f3 (diff) | |
download | glibc-dabd75b6a1180c2ca6a6f966f08cc00e8e72cce9.tar.gz glibc-dabd75b6a1180c2ca6a6f966f08cc00e8e72cce9.tar.xz glibc-dabd75b6a1180c2ca6a6f966f08cc00e8e72cce9.zip |
support: Define support_static_assert for use with C and C++
And update TEST_COMPARE to use it, to make it usable from C++.
Diffstat (limited to 'support')
-rw-r--r-- | support/check.h | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/support/check.h b/support/check.h index de8fce0dc1..a28e650aa3 100644 --- a/support/check.h +++ b/support/check.h @@ -86,6 +86,13 @@ void support_test_verify_exit_impl (int status, const char *file, int line, does not support reporting failures from a DSO. */ void support_record_failure (void); +/* Static assertion, under a common name for both C++ and C11. */ +#ifdef __cplusplus +# define support_static_assert static_assert +#else +# define support_static_assert _Static_assert +#endif + /* Compare the two integers LEFT and RIGHT and report failure if they are different. */ #define TEST_COMPARE(left, right) \ @@ -96,14 +103,14 @@ void support_record_failure (void); __left_type __left_value = (left); \ __right_type __right_value = (right); \ /* Prevent use with floating-point and boolean types. */ \ - _Static_assert ((__left_type) 1.0 == (__left_type) 1.5, \ - "left value has floating-point type"); \ - _Static_assert ((__right_type) 1.0 == (__right_type) 1.5, \ - "right value has floating-point type"); \ + support_static_assert ((__left_type) 1.0 == (__left_type) 1.5, \ + "left value has floating-point type"); \ + support_static_assert ((__right_type) 1.0 == (__right_type) 1.5, \ + "right value has floating-point type"); \ /* Prevent accidental use with larger-than-long long types. */ \ - _Static_assert (sizeof (__left_value) <= sizeof (long long), \ - "left value fits into long long"); \ - _Static_assert (sizeof (__right_value) <= sizeof (long long), \ + support_static_assert (sizeof (__left_value) <= sizeof (long long), \ + "left value fits into long long"); \ + support_static_assert (sizeof (__right_value) <= sizeof (long long), \ "right value fits into long long"); \ /* Make sure that integer conversions does not alter the sign. */ \ enum \ @@ -117,8 +124,8 @@ void support_record_failure (void); && (sizeof (__right_value) \ < sizeof (__left_value))) \ }; \ - _Static_assert (__left_is_unsigned == __right_is_unsigned \ - || __unsigned_left_converts_to_wider \ + support_static_assert (__left_is_unsigned == __right_is_unsigned \ + || __unsigned_left_converts_to_wider \ || __unsigned_right_converts_to_wider, \ "integer conversions may alter sign of operands"); \ /* Compare the value. */ \ |