Always use static_assert for compile-time assertions and remove META_ASSERT.
BUG=468139
Change-Id: I696ef307f2faa54bb72df66784bc79a055499987
Reviewed-on: https://chromium-review.googlesource.com/260776
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/common/debug.h b/src/common/debug.h
index dc3ac0a..5c04e78 100644
--- a/src/common/debug.h
+++ b/src/common/debug.h
@@ -162,23 +162,4 @@
#define HAS_DYNAMIC_TYPE(type, obj) true
#endif
-// A macro functioning as a compile-time assert to validate constant conditions
-
-#if (defined(_MSC_VER) && _MSC_VER >= 1600)
-#define ANGLE_HAS_STATIC_ASSERT
-#elif (defined(__GNUC__) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3))
-#define ANGLE_HAS_STATIC_ASSERT
-#elif defined(__clang__) && __has_feature(cxx_static_assert)
-#define ANGLE_HAS_STATIC_ASSERT
-#endif
-
-#if defined(ANGLE_HAS_STATIC_ASSERT)
-#define META_ASSERT_MSG(condition, msg) static_assert(condition, msg)
-#else
-#define META_ASSERT_CONCAT(a, b) a ## b
-#define META_ASSERT_CONCAT2(a, b) META_ASSERT_CONCAT(a, b)
-#define META_ASSERT_MSG(condition, msg) typedef int META_ASSERT_CONCAT2(COMPILE_TIME_ASSERT_, __LINE__)[static_cast<bool>(condition)?1:-1]
-#endif
-#define META_ASSERT(condition) META_ASSERT_MSG(condition, "compile time assertion failed.")
-
#endif // COMMON_DEBUG_H_
diff --git a/src/common/mathutil.h b/src/common/mathutil.h
index 5fba7ef..e096b1a 100644
--- a/src/common/mathutil.h
+++ b/src/common/mathutil.h
@@ -403,7 +403,7 @@
template <typename T>
inline float normalizedToFloat(T input)
{
- META_ASSERT(std::numeric_limits<T>::is_integer);
+ static_assert(std::numeric_limits<T>::is_integer, "T must be an integer.");
const float inverseMax = 1.0f / std::numeric_limits<T>::max();
return input * inverseMax;
@@ -412,8 +412,8 @@
template <unsigned int inputBitCount, typename T>
inline float normalizedToFloat(T input)
{
- META_ASSERT(std::numeric_limits<T>::is_integer);
- META_ASSERT(inputBitCount < (sizeof(T) * 8));
+ static_assert(std::numeric_limits<T>::is_integer, "T must be an integer.");
+ static_assert(inputBitCount < (sizeof(T) * 8), "T must have more bits than inputBitCount.");
const float inverseMax = 1.0f / ((1 << inputBitCount) - 1);
return input * inverseMax;
@@ -428,14 +428,15 @@
template <unsigned int outputBitCount, typename T>
inline T floatToNormalized(float input)
{
- META_ASSERT(outputBitCount < (sizeof(T) * 8));
+ static_assert(outputBitCount < (sizeof(T) * 8), "T must have more bits than outputBitCount.");
return ((1 << outputBitCount) - 1) * input + 0.5f;
}
template <unsigned int inputBitCount, unsigned int inputBitStart, typename T>
inline T getShiftedData(T input)
{
- META_ASSERT(inputBitCount + inputBitStart <= (sizeof(T) * 8));
+ static_assert(inputBitCount + inputBitStart <= (sizeof(T) * 8),
+ "T must have at least as many bits as inputBitCount + inputBitStart.");
const T mask = (1 << inputBitCount) - 1;
return (input >> inputBitStart) & mask;
}
@@ -443,7 +444,8 @@
template <unsigned int inputBitCount, unsigned int inputBitStart, typename T>
inline T shiftData(T input)
{
- META_ASSERT(inputBitCount + inputBitStart <= (sizeof(T) * 8));
+ static_assert(inputBitCount + inputBitStart <= (sizeof(T) * 8),
+ "T must have at least as many bits as inputBitCount + inputBitStart.");
const T mask = (1 << inputBitCount) - 1;
return (input & mask) << inputBitStart;
}
@@ -547,14 +549,14 @@
template <class T>
inline bool IsUnsignedAdditionSafe(T lhs, T rhs)
{
- META_ASSERT(!std::numeric_limits<T>::is_signed);
+ static_assert(!std::numeric_limits<T>::is_signed, "T must be unsigned.");
return (rhs <= std::numeric_limits<T>::max() - lhs);
}
template <class T>
inline bool IsUnsignedMultiplicationSafe(T lhs, T rhs)
{
- META_ASSERT(!std::numeric_limits<T>::is_signed);
+ static_assert(!std::numeric_limits<T>::is_signed, "T must be unsigned.");
return (lhs == T(0) || rhs == T(0) || (rhs <= std::numeric_limits<T>::max() / lhs));
}
diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp
index a3706e1..501e9c2 100644
--- a/src/common/utilities.cpp
+++ b/src/common/utilities.cpp
@@ -343,11 +343,11 @@
return -1;
}
-META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
-META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
-META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
-META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
-META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
+static_assert(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1, "Unexpected GL cube map enum value.");
+static_assert(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2, "Unexpected GL cube map enum value.");
+static_assert(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3, "Unexpected GL cube map enum value.");
+static_assert(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4, "Unexpected GL cube map enum value.");
+static_assert(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5, "Unexpected GL cube map enum value.");
bool IsCubeMapTextureTarget(GLenum target)
{
diff --git a/src/libANGLE/BinaryStream.h b/src/libANGLE/BinaryStream.h
index e0c1c9e..de71d6c 100644
--- a/src/libANGLE/BinaryStream.h
+++ b/src/libANGLE/BinaryStream.h
@@ -22,7 +22,7 @@
{
// c++11 STL is not available on OSX or Android
#if !defined(ANGLE_PLATFORM_APPLE) && !defined(ANGLE_PLATFORM_ANDROID)
- META_ASSERT(std::is_fundamental<T>::value);
+ static_assert(std::is_fundamental<T>::value, "T must be a fundamental type.");
#else
union { T dummy; } dummy;
static_cast<void>(dummy);
diff --git a/src/libANGLE/Config.cpp b/src/libANGLE/Config.cpp
index e89a1c2..ceb53db 100644
--- a/src/libANGLE/Config.cpp
+++ b/src/libANGLE/Config.cpp
@@ -125,10 +125,10 @@
return x.attribute < y.attribute; \
}
- META_ASSERT(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG);
+ static_assert(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG, "Unexpected EGL enum value.");
SORT(configCaveat);
- META_ASSERT(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER);
+ static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "Unexpected EGL enum value.");
SORT(colorBufferType);
// By larger total number of color bits, only considering those that are requested to be > 0.
diff --git a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
index e89a8f9..744aa81 100644
--- a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
+++ b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
@@ -17,7 +17,7 @@
#include "libANGLE/formatutils.h"
// For use with ArrayString, see angleutils.h
-META_ASSERT(GL_INVALID_INDEX == UINT_MAX);
+static_assert(GL_INVALID_INDEX == UINT_MAX, "GL_INVALID_INDEX must be equal to the max unsigned int.");
using namespace gl;
diff --git a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
index 1098941..c7a1b6b 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
@@ -928,8 +928,8 @@
// Max D3D11 stencil reference value is 0xFF, corresponding to the max 8 bits in a stencil buffer
// GL specifies we should clamp the ref value to the nearest bit depth when doing stencil ops
- META_ASSERT(D3D11_DEFAULT_STENCIL_READ_MASK == 0xFF);
- META_ASSERT(D3D11_DEFAULT_STENCIL_WRITE_MASK == 0xFF);
+ static_assert(D3D11_DEFAULT_STENCIL_READ_MASK == 0xFF, "Unexpected value of D3D11_DEFAULT_STENCIL_READ_MASK");
+ static_assert(D3D11_DEFAULT_STENCIL_WRITE_MASK == 0xFF, "Unexpected value of D3D11_DEFAULT_STENCIL_WRITE_MASK");
UINT dxStencilRef = std::min<UINT>(stencilRef, 0xFFu);
mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, dxStencilRef);
@@ -2170,7 +2170,7 @@
{
// Use the adapter LUID as our adapter ID
// This number is local to a machine is only guaranteed to be unique between restarts
- META_ASSERT(sizeof(LUID) <= sizeof(GUID));
+ static_assert(sizeof(LUID) <= sizeof(GUID), "Size of GUID must be at least as large as LUID.");
GUID adapterId = {0};
memcpy(&adapterId, &mAdapterDescription.AdapterLuid, sizeof(LUID));
return adapterId;
@@ -3143,9 +3143,10 @@
ColorWriteFunction colorWriteFunction = GetColorWriteFunction(params.format, params.type);
uint8_t temp[16]; // Maximum size of any Color<T> type used.
- META_ASSERT(sizeof(temp) >= sizeof(gl::ColorF) &&
- sizeof(temp) >= sizeof(gl::ColorUI) &&
- sizeof(temp) >= sizeof(gl::ColorI));
+ static_assert(sizeof(temp) >= sizeof(gl::ColorF) &&
+ sizeof(temp) >= sizeof(gl::ColorUI) &&
+ sizeof(temp) >= sizeof(gl::ColorI),
+ "Unexpected size of gl::Color struct.");
for (int y = 0; y < params.area.height; y++)
{
diff --git a/src/libANGLE/renderer/d3d/d3d11/copyvertex.inl b/src/libANGLE/renderer/d3d/d3d11/copyvertex.inl
index e92056f..60678d7 100644
--- a/src/libANGLE/renderer/d3d/d3d11/copyvertex.inl
+++ b/src/libANGLE/renderer/d3d/d3d11/copyvertex.inl
@@ -127,7 +127,8 @@
}
// 4-component output formats would need special padding in the alpha channel.
- META_ASSERT(!(inputComponentCount < 4 && outputComponentCount == 4));
+ static_assert(!(inputComponentCount < 4 && outputComponentCount == 4),
+ "An inputComponentCount less than 4 and an outputComponentCount equal to 4 is not supported.");
for (size_t j = inputComponentCount; j < outputComponentCount; j++)
{
@@ -167,7 +168,8 @@
}
// This would require special padding.
- META_ASSERT(!(inputComponentCount < 4 && outputComponentCount == 4));
+ static_assert(!(inputComponentCount < 4 && outputComponentCount == 4),
+ "An inputComponentCount less than 4 and an outputComponentCount equal to 4 is not supported.");
for (size_t j = inputComponentCount; j < outputComponentCount; j++)
{
diff --git a/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.cpp b/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.cpp
index f7c2acd..754acd8 100644
--- a/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/renderer11_utils.cpp
@@ -581,8 +581,8 @@
{
// D3D11 allows up to 2^32 elements, but we report max signed int for convenience since that's what's
// returned from glGetInteger
- META_ASSERT(D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32);
- META_ASSERT(D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32);
+ static_assert(D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value.");
+ static_assert(D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value.");
switch (featureLevel)
{
@@ -603,8 +603,8 @@
{
// D3D11 allows up to 2^32 elements, but we report max signed int for convenience since that's what's
// returned from glGetInteger
- META_ASSERT(D3D11_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32);
- META_ASSERT(D3D10_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32);
+ static_assert(D3D11_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value.");
+ static_assert(D3D10_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value.");
switch (featureLevel)
{
@@ -693,7 +693,7 @@
static size_t GetMaximumVertexOutputVectors(D3D_FEATURE_LEVEL featureLevel)
{
- META_ASSERT(gl::IMPLEMENTATION_MAX_VARYING_VECTORS == D3D11_VS_OUTPUT_REGISTER_COUNT);
+ static_assert(gl::IMPLEMENTATION_MAX_VARYING_VECTORS == D3D11_VS_OUTPUT_REGISTER_COUNT, "Unexpected D3D11 constant value.");
switch (featureLevel)
{
diff --git a/src/libANGLE/validationEGL.cpp b/src/libANGLE/validationEGL.cpp
index 102506d..640ca77 100644
--- a/src/libANGLE/validationEGL.cpp
+++ b/src/libANGLE/validationEGL.cpp
@@ -132,8 +132,8 @@
break;
case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR:
- META_ASSERT(EGL_LOSE_CONTEXT_ON_RESET_EXT == EGL_LOSE_CONTEXT_ON_RESET_KHR);
- META_ASSERT(EGL_NO_RESET_NOTIFICATION_EXT == EGL_NO_RESET_NOTIFICATION_KHR);
+ static_assert(EGL_LOSE_CONTEXT_ON_RESET_EXT == EGL_LOSE_CONTEXT_ON_RESET_KHR, "EGL extension enums not equal.");
+ static_assert(EGL_NO_RESET_NOTIFICATION_EXT == EGL_NO_RESET_NOTIFICATION_KHR, "EGL extension enums not equal.");
// same as EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, fall through
case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT:
if (!display->getExtensions().createContextRobustness)
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 77dc273..76232fd 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -92,7 +92,8 @@
bool ValidFramebufferTarget(GLenum target)
{
- META_ASSERT(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER);
+ static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER,
+ "ANGLE framebuffer enums must equal the ES3 framebuffer enums.");
switch (target)
{
@@ -209,8 +210,8 @@
bool ValidQueryType(const Context *context, GLenum queryType)
{
- META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT);
- META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT);
+ static_assert(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT, "GL extension enums not equal.");
+ static_assert(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, "GL extension enums not equal.");
switch (queryType)
{
@@ -679,7 +680,8 @@
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
// Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
// the same constant.
- META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
+ static_assert(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE,
+ "ANGLE extension enums not equal to GL enums.");
return true;
case GL_VERTEX_ATTRIB_ARRAY_INTEGER: