Convert COMPILE_ASSERT to static_assert

(Perhaps I should have just left it in mini_chromium, but anyway.)

R=mark@chromium.org
BUG=crashpad:1

Review URL: https://codereview.chromium.org/615923004
This commit is contained in:
Scott Graham 2014-10-01 12:29:01 -07:00
parent 5906513e30
commit d198c50abe
18 changed files with 66 additions and 70 deletions

View File

@ -14,7 +14,6 @@
#include "client/simple_string_dictionary.h"
#include "base/basictypes.h"
#include "util/stdlib/cxx.h"
#if CXX_LIBRARY_VERSION >= 2011
@ -29,9 +28,9 @@ typedef TSimpleStringDictionary<1, 1, 1> SimpleStringDictionaryForAssertion;
#if CXX_LIBRARY_VERSION >= 2011
// In C++11, check that TSimpleStringDictionary has standard layout, which is
// what is actually important.
COMPILE_ASSERT(
static_assert(
std::is_standard_layout<SimpleStringDictionaryForAssertion>::value,
SimpleStringDictionary_must_be_standard_layout);
"SimpleStringDictionary must be standard layout");
#else
// In C++98 (ISO 14882), section 9.5.1 says that a union cannot have a member
// with a non-trivial ctor, copy ctor, dtor, or assignment operator. Use this

View File

@ -1943,8 +1943,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED = COMPILE_ASSERT(a,b)= \
DOXYGEN \
PREDEFINED = DOXYGEN \
__attribute__(x)=
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this

View File

@ -47,8 +47,8 @@ void MinidumpSystemInfoWriter::SetCPUX86Vendor(uint32_t ebx,
system_info_.ProcessorArchitecture ==
kMinidumpCPUArchitectureX86Win64);
COMPILE_ASSERT(arraysize(system_info_.Cpu.X86CpuInfo.VendorId) == 3,
vendor_id_must_have_3_elements);
static_assert(arraysize(system_info_.Cpu.X86CpuInfo.VendorId) == 3,
"VendorId must have 3 elements");
system_info_.Cpu.X86CpuInfo.VendorId[0] = ebx;
system_info_.Cpu.X86CpuInfo.VendorId[1] = edx;
@ -61,9 +61,9 @@ void MinidumpSystemInfoWriter::SetCPUX86VendorString(
CHECK_EQ(vendor.size(), sizeof(system_info_.Cpu.X86CpuInfo.VendorId));
uint32_t registers[3];
COMPILE_ASSERT(
static_assert(
sizeof(registers) == sizeof(system_info_.Cpu.X86CpuInfo.VendorId),
vendor_id_sizes_must_be_equal);
"VendorId sizes must be equal");
for (size_t index = 0; index < arraysize(registers); ++index) {
memcpy(&registers[index],
@ -105,9 +105,8 @@ void MinidumpSystemInfoWriter::SetCPUOtherFeatures(uint64_t features_0,
system_info_.ProcessorArchitecture !=
kMinidumpCPUArchitectureX86Win64);
COMPILE_ASSERT(
arraysize(system_info_.Cpu.OtherCpuInfo.ProcessorFeatures) == 2,
processor_features_must_have_2_elements);
static_assert(arraysize(system_info_.Cpu.OtherCpuInfo.ProcessorFeatures) == 2,
"ProcessorFeatures must have 2 elements");
system_info_.Cpu.OtherCpuInfo.ProcessorFeatures[0] = features_0;
system_info_.Cpu.OtherCpuInfo.ProcessorFeatures[1] = features_1;

View File

@ -25,11 +25,11 @@
namespace crashpad {
// Ensure type compatibility between WritableIoVec and iovec.
COMPILE_ASSERT(sizeof(WritableIoVec) == sizeof(iovec), WritableIoVec_size);
COMPILE_ASSERT(offsetof(WritableIoVec, iov_base) == offsetof(iovec, iov_base),
WritableIoVec_base_offset);
COMPILE_ASSERT(offsetof(WritableIoVec, iov_len) == offsetof(iovec, iov_len),
WritableIoVec_len_offset);
static_assert(sizeof(WritableIoVec) == sizeof(iovec), "WritableIoVec size");
static_assert(offsetof(WritableIoVec, iov_base) == offsetof(iovec, iov_base),
"WritableIoVec base offset");
static_assert(offsetof(WritableIoVec, iov_len) == offsetof(iovec, iov_len),
"WritableIoVec len offset");
FileWriter::FileWriter() : fd_() {
}

View File

@ -354,8 +354,8 @@ TEST(StringFileWriter, SeekInvalid) {
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.string().empty());
COMPILE_ASSERT(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3,
three_must_be_invalid_for_whence);
static_assert(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3,
"3 must be invalid for whence");
EXPECT_LT(writer.Seek(0, 3), 0);
writer.Reset();

View File

@ -328,7 +328,7 @@ const process_types::section* MachOImageReader::GetSectionAtIndex(
mach_vm_address_t* address) const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
COMPILE_ASSERT(NO_SECT == 0, no_sect_must_be_zero);
static_assert(NO_SECT == 0, "NO_SECT must be zero");
if (index == NO_SECT) {
LOG(WARNING) << "section index " << index << " out of range";
return NULL;

View File

@ -237,9 +237,9 @@ std::string MachOImageSegmentReader::SegmentNameString(
const char* segment_name_c) {
// This is used to interpret the segname field of both the segment_command and
// section structures, so be sure that theyre identical.
COMPILE_ASSERT(sizeof(process_types::segment_command::segname) ==
sizeof(process_types::section::segname),
sizes_must_be_equal);
static_assert(sizeof(process_types::segment_command::segname) ==
sizeof(process_types::section::segname),
"sizes must be equal");
return SizeLimitedCString(segment_name_c,
sizeof(process_types::segment_command::segname));

View File

@ -1114,7 +1114,7 @@ TEST(ExcServerVariants, ExcCrashRecoverOriginalException) {
// Now make sure that ExcCrashRecoverOriginalException() properly ignores
// optional arguments.
COMPILE_ASSERT(arraysize(kTestData) >= 1, must_have_something_to_test);
static_assert(arraysize(kTestData) >= 1, "must have something to test");
const TestData& test_data = kTestData[0];
EXPECT_EQ(test_data.exception,
ExcCrashRecoverOriginalException(test_data.code_0, NULL, NULL));

View File

@ -696,8 +696,8 @@ TEST(MachMessageServer, PersistentNonblockingFourMessages) {
// child_wait_for_parent_pipe_early is used to make the child wait until the
// parent is ready.
const size_t kTransactionCount = 4;
COMPILE_ASSERT(kTransactionCount <= MACH_PORT_QLIMIT_DEFAULT,
must_not_exceed_queue_limit);
static_assert(kTransactionCount <= MACH_PORT_QLIMIT_DEFAULT,
"must not exceed queue limit");
TestMachMessageServer::Options options;
options.parent_wait_for_child_pipe = true;

View File

@ -42,8 +42,8 @@ const char* kExceptionNames[] = {
"RESOURCE",
"GUARD",
};
COMPILE_ASSERT(arraysize(kExceptionNames) == EXC_TYPES_COUNT,
kExceptionNames_length);
static_assert(arraysize(kExceptionNames) == EXC_TYPES_COUNT,
"kExceptionNames length");
const char kExcPrefix[] = "EXC_";
const char kExcMaskPrefix[] = "EXC_MASK_";

View File

@ -27,11 +27,11 @@
namespace crashpad {
COMPILE_ASSERT(sizeof(UUID) == 16, UUID_must_be_16_bytes);
static_assert(sizeof(UUID) == 16, "UUID must be 16 bytes");
#if CXX_LIBRARY_VERSION >= 2011
COMPILE_ASSERT(std::is_standard_layout<UUID>::value,
UUID_must_be_standard_layout);
static_assert(std::is_standard_layout<UUID>::value,
"UUID must be standard layout");
#endif
UUID::UUID() : data_1(0), data_2(0), data_3(0), data_4(), data_5() {

View File

@ -30,8 +30,8 @@ template <typename ValueType, typename SizeType = ValueType>
class CheckedRange {
public:
CheckedRange(ValueType base, SizeType size) {
COMPILE_ASSERT(!std::numeric_limits<SizeType>::is_signed,
SizeType_must_be_unsigned);
static_assert(!std::numeric_limits<SizeType>::is_signed,
"SizeType must be unsigned");
SetRange(base, size);
}

View File

@ -17,7 +17,6 @@
#include <stdint.h>
#include "base/basictypes.h"
#include "build/build_config.h"
namespace crashpad {
@ -46,7 +45,7 @@ struct uint128_struct {
#endif
};
COMPILE_ASSERT(sizeof(uint128_struct) == 16, uint128_must_be_16_bytes);
static_assert(sizeof(uint128_struct) == 16, "uint128 must be 16 bytes");
} // namespace crashpad

View File

@ -30,7 +30,7 @@ TEST(Int128, UInt128) {
#endif
uint128_struct uint128;
COMPILE_ASSERT(sizeof(uint128) == sizeof(kBytes), sizes_must_be_equal);
static_assert(sizeof(uint128) == sizeof(kBytes), "sizes must be equal");
uint128 = bit_cast<uint128_struct>(kBytes);

View File

@ -99,9 +99,9 @@ const char* kSignalNames[] = {
};
#if defined(OS_LINUX)
// NSIG is 64 to account for real-time signals.
COMPILE_ASSERT(arraysize(kSignalNames) == 32, kSignalNames_length);
static_assert(arraysize(kSignalNames) == 32, "kSignalNames length");
#else
COMPILE_ASSERT(arraysize(kSignalNames) == NSIG, kSignalNames_length);
static_assert(arraysize(kSignalNames) == NSIG, "kSignalNames length");
#endif
const char kSigPrefix[] = "SIG";

View File

@ -21,20 +21,19 @@
#include <limits>
#include "base/basictypes.h"
#include "base/logging.h"
#include "util/stdlib/cxx.h"
// CONSTEXPR_COMPILE_ASSERT will be a normal COMPILE_ASSERT if the C++ library
// is the C++11 library. If using an older C++ library when compiling C++11
// code, the std::numeric_limits<>::min() and max() functions will not be
// marked as constexpr, and thus wont be usable with C++11s static_assert().
// In that case, a run-time CHECK() will have to do.
// CONSTEXPR_STATIC_ASSERT will be a normal static_assert if the C++ library is
// the C++11 library. If using an older C++ library when compiling C++11 code,
// the std::numeric_limits<>::min() and max() functions will not be marked as
// constexpr, and thus wont be usable with C++11s static_assert(). In that
// case, a run-time CHECK() will have to do.
#if CXX_LIBRARY_VERSION >= 2011
#define CONSTEXPR_COMPILE_ASSERT(condition, message) \
COMPILE_ASSERT(condition, message)
#define CONSTEXPR_STATIC_ASSERT(condition, message) \
static_assert(condition, message)
#else
#define CONSTEXPR_COMPILE_ASSERT(condition, message) CHECK(condition)
#define CONSTEXPR_STATIC_ASSERT(condition, message) CHECK(condition) << message
#endif
namespace {
@ -44,22 +43,22 @@ struct StringToIntegerTraits {
typedef TIntType IntType;
typedef TLongType LongType;
static void TypeCheck() {
COMPILE_ASSERT(std::numeric_limits<TIntType>::is_integer &&
std::numeric_limits<TLongType>::is_integer,
IntType_and_LongType_must_be_integer);
COMPILE_ASSERT(std::numeric_limits<TIntType>::is_signed ==
std::numeric_limits<TLongType>::is_signed,
IntType_and_LongType_signedness_must_agree);
CONSTEXPR_COMPILE_ASSERT(std::numeric_limits<TIntType>::min() >=
std::numeric_limits<TLongType>::min() &&
std::numeric_limits<TIntType>::min() <
std::numeric_limits<TLongType>::max(),
IntType_min_must_be_in_LongType_range);
CONSTEXPR_COMPILE_ASSERT(std::numeric_limits<TIntType>::max() >
std::numeric_limits<TLongType>::min() &&
std::numeric_limits<TIntType>::max() <=
std::numeric_limits<TLongType>::max(),
IntType_max_must_be_in_LongType_range);
static_assert(std::numeric_limits<TIntType>::is_integer &&
std::numeric_limits<TLongType>::is_integer,
"IntType and LongType must be integer");
static_assert(std::numeric_limits<TIntType>::is_signed ==
std::numeric_limits<TLongType>::is_signed,
"IntType and LongType signedness must agree");
CONSTEXPR_STATIC_ASSERT(std::numeric_limits<TIntType>::min() >=
std::numeric_limits<TLongType>::min() &&
std::numeric_limits<TIntType>::min() <
std::numeric_limits<TLongType>::max(),
"IntType min must be in LongType range");
CONSTEXPR_STATIC_ASSERT(std::numeric_limits<TIntType>::max() >
std::numeric_limits<TLongType>::min() &&
std::numeric_limits<TIntType>::max() <=
std::numeric_limits<TLongType>::max(),
"IntType max must be in LongType range");
}
};
@ -67,8 +66,8 @@ template <typename TIntType, typename TLongType>
struct StringToSignedIntegerTraits
: public StringToIntegerTraits<TIntType, TLongType> {
static void TypeCheck() {
COMPILE_ASSERT(std::numeric_limits<TIntType>::is_signed,
StringToSignedTraits_IntType_must_be_signed);
static_assert(std::numeric_limits<TIntType>::is_signed,
"StringToSignedTraits IntType must be signed");
return super::TypeCheck();
}
static bool IsNegativeOverflow(TLongType value) {
@ -83,8 +82,8 @@ template <typename TIntType, typename TLongType>
struct StringToUnsignedIntegerTraits
: public StringToIntegerTraits<TIntType, TLongType> {
static void TypeCheck() {
COMPILE_ASSERT(!std::numeric_limits<TIntType>::is_signed,
StringToUnsignedTraits_IntType_must_be_unsigned);
static_assert(!std::numeric_limits<TIntType>::is_signed,
"StringToUnsignedTraits IntType must be unsigned");
return super::TypeCheck();
}
static bool IsNegativeOverflow(TLongType value) { return false; }

View File

@ -18,6 +18,7 @@
#include <algorithm>
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "gtest/gtest.h"

View File

@ -72,9 +72,9 @@ void MultiprocessExec::PreFork() {
void MultiprocessExec::MultiprocessChild() {
// Make sure that stdin, stdout, and stderr are FDs 0, 1, and 2, respectively.
// All FDs above this will be closed.
COMPILE_ASSERT(STDIN_FILENO == 0, stdin_must_be_fd_0);
COMPILE_ASSERT(STDOUT_FILENO == 1, stdout_must_be_fd_1);
COMPILE_ASSERT(STDERR_FILENO == 2, stderr_must_be_fd_2);
static_assert(STDIN_FILENO == 0, "stdin must be fd 0");
static_assert(STDOUT_FILENO == 1, "stdout must be fd 1");
static_assert(STDERR_FILENO == 2, "stderr must be fd 2");
// Move the read pipe to stdin.
int read_fd = ReadPipeFD();