8275717: Reimplement STATIC_ASSERT to use static_assert

Reviewed-by: stuefe, eosterlund, kbarrett
This commit is contained in:
Stefan Karlsson 2021-10-25 09:07:51 +00:00
parent f6232982b9
commit 0bcc1749ea

View File

@ -174,22 +174,7 @@ void report_untested(const char* file, int line, const char* message);
void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);
// Compile-time asserts. Cond must be a compile-time constant expression that
// is convertible to bool. STATIC_ASSERT() can be used anywhere a declaration
// may appear.
//
// Implementation Note: STATIC_ASSERT_FAILURE<true> provides a value member
// rather than type member that could be used directly in the typedef, because
// a type member would require conditional use of "typename", depending on
// whether Cond is dependent or not. The use of a value member leads to the
// use of an array type.
template<bool x> struct STATIC_ASSERT_FAILURE;
template<> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
#define STATIC_ASSERT(Cond) \
typedef char PASTE_TOKENS(STATIC_ASSERT_DUMMY_TYPE_, __LINE__)[ \
STATIC_ASSERT_FAILURE< (Cond) >::value ]
#define STATIC_ASSERT(Cond) static_assert((Cond), #Cond)
// out of memory reporting
void report_java_out_of_memory(const char* message);