Skip to content

Commit

Permalink
replace COMPILE_ASSERT with static_assert in net/
Browse files Browse the repository at this point in the history
BUG=442514
TBR=abarth

Review URL: https://codereview.chromium.org/826973002

Cr-Commit-Position: refs/heads/master@{#312238}
  • Loading branch information
mostynb authored and Commit bot committed Jan 20, 2015
1 parent 9d51ce5 commit 91e0da9
Show file tree
Hide file tree
Showing 60 changed files with 164 additions and 163 deletions.
3 changes: 2 additions & 1 deletion net/base/mime_sniffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ struct MagicNumber {

template <int MagicSize, int MaskSize>
class VerifySizes {
COMPILE_ASSERT(MagicSize == MaskSize, sizes_must_be_equal);
static_assert(MagicSize == MaskSize, "sizes must be equal");

public:
enum { SIZES = MagicSize };
};
Expand Down
7 changes: 3 additions & 4 deletions net/base/network_change_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,9 @@ const char* NetworkChangeNotifier::ConnectionTypeToString(
"CONNECTION_NONE",
"CONNECTION_BLUETOOTH"
};
COMPILE_ASSERT(
arraysize(kConnectionTypeNames) ==
NetworkChangeNotifier::CONNECTION_LAST + 1,
ConnectionType_name_count_mismatch);
static_assert(arraysize(kConnectionTypeNames) ==
NetworkChangeNotifier::CONNECTION_LAST + 1,
"ConnectionType name count should match");
if (type < CONNECTION_UNKNOWN || type > CONNECTION_LAST) {
NOTREACHED();
return "CONNECTION_INVALID";
Expand Down
10 changes: 4 additions & 6 deletions net/base/prioritized_dispatcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ namespace {

// We rely on the priority enum values being sequential having starting at 0,
// and increasing for higher priorities.
COMPILE_ASSERT(MINIMUM_PRIORITY == 0u &&
MINIMUM_PRIORITY == IDLE &&
IDLE < LOWEST &&
LOWEST < HIGHEST &&
HIGHEST <= MAXIMUM_PRIORITY,
priority_indexes_incompatible);
static_assert(MINIMUM_PRIORITY == 0u && MINIMUM_PRIORITY == IDLE &&
IDLE < LOWEST && LOWEST < HIGHEST &&
HIGHEST <= MAXIMUM_PRIORITY,
"priority indexes incompatible");

class PrioritizedDispatcherTest : public testing::Test {
public:
Expand Down
2 changes: 1 addition & 1 deletion net/cert/crl_set_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ bool CRLSetStorage::Parse(base::StringPiece data,
// anything by doing this.
#if defined(__BYTE_ORDER)
// Linux check
COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, assumes_little_endian);
static_assert(__BYTE_ORDER == __LITTLE_ENDIAN, "assumes little endian");
#elif defined(__BIG_ENDIAN__)
// Mac check
#error assumes little endian
Expand Down
4 changes: 2 additions & 2 deletions net/cookies/cookie_monster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1890,8 +1890,8 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it,
// Ideally, this would be asserted up where we define ChangeCauseMapping,
// but DeletionCause's visibility (or lack thereof) forces us to make
// this check here.
COMPILE_ASSERT(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1,
ChangeCauseMapping_size_not_eq_DeletionCause_enum_size);
static_assert(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1,
"ChangeCauseMapping size should match DeletionCause size");

// See InitializeHistograms() for details.
if (deletion_cause != DELETE_COOKIE_DONT_RECORD)
Expand Down
3 changes: 2 additions & 1 deletion net/disk_cache/blockfile/backend_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,8 @@ EntryImpl* BackendImpl::OpenNextEntryImpl(Rankings::Iterator* iterator) {
}

bool BackendImpl::SetMaxSize(int max_bytes) {
COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model);
static_assert(sizeof(max_bytes) == sizeof(max_size_),
"unsupported int model");
if (max_bytes < 0)
return false;

Expand Down
3 changes: 2 additions & 1 deletion net/disk_cache/blockfile/backend_impl_v3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ int BackendImplV3::Init(const CompletionCallback& callback) {
// ------------------------------------------------------------------------

bool BackendImplV3::SetMaxSize(int max_bytes) {
COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model);
static_assert(sizeof(max_bytes) == sizeof(max_size_),
"unsupported int model");
if (max_bytes < 0)
return false;

Expand Down
2 changes: 1 addition & 1 deletion net/disk_cache/blockfile/block_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ bool BlockFiles::GrowBlockFile(MappedFile* file, BlockFileHeader* header) {
}

MappedFile* BlockFiles::FileForNewBlock(FileType block_type, int block_count) {
COMPILE_ASSERT(RANKINGS == 1, invalid_file_type);
static_assert(RANKINGS == 1, "invalid file type");
MappedFile* file = block_files_[block_type - 1];
BlockHeader file_header(file);

Expand Down
4 changes: 2 additions & 2 deletions net/disk_cache/blockfile/disk_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct EntryStore {
char key[256 - 24 * 4]; // null terminated
};

COMPILE_ASSERT(sizeof(EntryStore) == 256, bad_EntyStore);
static_assert(sizeof(EntryStore) == 256, "bad EntryStore");
const int kMaxInternalKeyLength = 4 * sizeof(EntryStore) -
offsetof(EntryStore, key) - 1;

Expand Down Expand Up @@ -146,7 +146,7 @@ struct RankingsNode {
};
#pragma pack(pop)

COMPILE_ASSERT(sizeof(RankingsNode) == 36, bad_RankingsNode);
static_assert(sizeof(RankingsNode) == 36, "bad RankingsNode");

} // namespace disk_cache

Expand Down
6 changes: 3 additions & 3 deletions net/disk_cache/blockfile/disk_format_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct BlockFileHeader {
AllocBitmap allocation_map;
};

COMPILE_ASSERT(sizeof(BlockFileHeader) == kBlockHeaderSize, bad_header);
static_assert(sizeof(BlockFileHeader) == kBlockHeaderSize, "bad header");

// Sparse data support:
// We keep a two level hierarchy to enable sparse data for an entry: the first
Expand Down Expand Up @@ -124,8 +124,8 @@ struct SparseData {

// The number of blocks stored by a child entry.
const int kNumSparseBits = 1024;
COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8,
Invalid_SparseData_bitmap);
static_assert(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8,
"invalid SparseData bitmap");

} // namespace disk_cache

Expand Down
14 changes: 7 additions & 7 deletions net/disk_cache/blockfile/disk_format_v3.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct IndexBitmap {
IndexHeaderV3 header;
uint32 bitmap[kBaseBitmapBytes / 4]; // First page of the bitmap.
};
COMPILE_ASSERT(sizeof(IndexBitmap) == 4096, bad_IndexHeader);
static_assert(sizeof(IndexBitmap) == 4096, "bad IndexHeader");

// Possible states for a given entry.
enum EntryState {
Expand All @@ -109,7 +109,7 @@ enum EntryState {
ENTRY_FIXING, // Inconsistent state. The entry is being verified.
ENTRY_USED // The slot is in use (entry is present).
};
COMPILE_ASSERT(ENTRY_USED <= 7, state_uses_3_bits);
static_assert(ENTRY_USED <= 7, "state uses 3 bits");

enum EntryGroup {
ENTRY_NO_USE = 0, // The entry has not been reused.
Expand All @@ -118,7 +118,7 @@ enum EntryGroup {
ENTRY_RESERVED, // Reserved for future use.
ENTRY_EVICTED // The entry was deleted.
};
COMPILE_ASSERT(ENTRY_USED <= 7, group_uses_3_bits);
static_assert(ENTRY_USED <= 7, "group uses 3 bits");

#pragma pack(push, 1)
struct IndexCell {
Expand Down Expand Up @@ -183,15 +183,15 @@ struct IndexCell {
uint64 first_part;
uint8 last_part;
};
COMPILE_ASSERT(sizeof(IndexCell) == 9, bad_IndexCell);
static_assert(sizeof(IndexCell) == 9, "bad IndexCell");

const int kCellsPerBucket = 4;
struct IndexBucket {
IndexCell cells[kCellsPerBucket];
int32 next;
uint32 hash; // The high order byte is reserved (should be zero).
};
COMPILE_ASSERT(sizeof(IndexBucket) == 44, bad_IndexBucket);
static_assert(sizeof(IndexBucket) == 44, "bad IndexBucket");
const int kBytesPerCell = 44 / kCellsPerBucket;

// The main cache index. Backed by a file named index_tb1.
Expand Down Expand Up @@ -225,7 +225,7 @@ struct EntryRecord {
int32 pad[3];
uint32 self_hash;
};
COMPILE_ASSERT(sizeof(EntryRecord) == 104, bad_EntryRecord);
static_assert(sizeof(EntryRecord) == 104, "bad EntryRecord");

struct ShortEntryRecord {
uint32 hash;
Expand All @@ -239,7 +239,7 @@ struct ShortEntryRecord {
uint32 long_hash[5];
uint32 self_hash;
};
COMPILE_ASSERT(sizeof(ShortEntryRecord) == 48, bad_ShortEntryRecord);
static_assert(sizeof(ShortEntryRecord) == 48, "bad ShortEntryRecord");

} // namespace disk_cache

Expand Down
2 changes: 1 addition & 1 deletion net/disk_cache/blockfile/entry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ std::string EntryImpl::GetKey() const {
if (address.is_block_file())
offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;

COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
static_assert(kNumStreams == kKeyFileIndex, "invalid key index");
File* key_file = const_cast<EntryImpl*>(this)->GetBackingFile(address,
kKeyFileIndex);
if (!key_file)
Expand Down
2 changes: 1 addition & 1 deletion net/disk_cache/blockfile/entry_impl_v3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ std::string EntryImplV3::GetKey() const {
if (address.is_block_file())
offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;

COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
static_assert(kNumStreams == kKeyFileIndex, "invalid key index");
File* key_file = const_cast<EntryImpl*>(this)->GetBackingFile(address,
kKeyFileIndex);
if (!key_file)
Expand Down
3 changes: 2 additions & 1 deletion net/disk_cache/blockfile/file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct MyOverlapped {
disk_cache::FileIOCallback* callback_;
};

COMPILE_ASSERT(!offsetof(MyOverlapped, context_), starts_with_overlapped);
static_assert(offsetof(MyOverlapped, context_) == 0,
"should start with overlapped");

// Helper class to handle the IO completion notifications from the message loop.
class CompletionHandler : public base::MessageLoopForIO::IOHandler {
Expand Down
10 changes: 5 additions & 5 deletions net/disk_cache/blockfile/stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct OnDiskStats {
int data_sizes[disk_cache::Stats::kDataSizesLength];
int64 counters[disk_cache::Stats::MAX_COUNTER];
};
COMPILE_ASSERT(sizeof(OnDiskStats) < 512, needs_more_than_2_blocks);
static_assert(sizeof(OnDiskStats) < 512, "needs more than 2 blocks");

// Returns the "floor" (as opposed to "ceiling") of log base 2 of number.
int LogBase2(int32 number) {
Expand Down Expand Up @@ -67,8 +67,8 @@ static const char* kCounterNames[] = {
"Doom recent entries",
"unused"
};
COMPILE_ASSERT(arraysize(kCounterNames) == disk_cache::Stats::MAX_COUNTER,
update_the_names);
static_assert(arraysize(kCounterNames) == disk_cache::Stats::MAX_COUNTER,
"update the names");

} // namespace

Expand Down Expand Up @@ -155,7 +155,7 @@ void Stats::InitSizeHistogram() {
int Stats::StorageSize() {
// If we have more than 512 bytes of counters, change kDiskSignature so we
// don't overwrite something else (LoadStats must fail).
COMPILE_ASSERT(sizeof(OnDiskStats) <= 256 * 2, use_more_blocks);
static_assert(sizeof(OnDiskStats) <= 256 * 2, "use more blocks");
return 256 * 2;
}

Expand Down Expand Up @@ -300,7 +300,7 @@ int Stats::GetStatsBucket(int32 size) {
// From this point on, use a logarithmic scale.
int result = LogBase2(size) + 1;

COMPILE_ASSERT(kDataSizesLength > 16, update_the_scale);
static_assert(kDataSizesLength > 16, "update the scale");
if (result >= kDataSizesLength)
result = kDataSizesLength - 1;

Expand Down
3 changes: 2 additions & 1 deletion net/disk_cache/entry_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ void DiskCacheEntryTest::StreamAccess() {
ASSERT_TRUE(NULL != entry);
const int kReadBufferSize = 600;
const int kFinalReadSize = kBufferSize - kReadBufferSize;
COMPILE_ASSERT(kFinalReadSize < kReadBufferSize, should_be_exactly_two_reads);
static_assert(kFinalReadSize < kReadBufferSize,
"should be exactly two reads");
scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kReadBufferSize));
for (int i = 0; i < kNumStreams; i++) {
memset(buffer2->data(), 0, kReadBufferSize);
Expand Down
3 changes: 2 additions & 1 deletion net/disk_cache/memory/mem_backend_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ bool MemBackendImpl::Init() {
}

bool MemBackendImpl::SetMaxSize(int max_bytes) {
COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model);
static_assert(sizeof(max_bytes) == sizeof(max_size_),
"unsupported int model");
if (max_bytes < 0)
return false;

Expand Down
16 changes: 8 additions & 8 deletions net/disk_cache/simple/simple_entry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ SimpleEntryImpl::SimpleEntryImpl(net::CacheType cache_type,
net_log_(net::BoundNetLog::Make(
net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY)),
stream_0_data_(new net::GrowableIOBuffer()) {
COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_end_offset_),
arrays_should_be_same_size);
COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_),
arrays_should_be_same_size);
COMPILE_ASSERT(arraysize(data_size_) == arraysize(have_written_),
arrays_should_be_same_size);
COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc_check_state_),
arrays_should_be_same_size);
static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_),
"arrays should be the same size");
static_assert(arraysize(data_size_) == arraysize(crc32s_),
"arrays should be the same size");
static_assert(arraysize(data_size_) == arraysize(have_written_),
"arrays should be the same size");
static_assert(arraysize(data_size_) == arraysize(crc_check_state_),
"arrays should be the same size");
MakeUninitialized();
net_log_.BeginEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY,
CreateNetLogSimpleEntryConstructionCallback(this));
Expand Down
2 changes: 1 addition & 1 deletion net/disk_cache/simple/simple_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NET_EXPORT_PRIVATE EntryMetadata {
uint32 last_used_time_seconds_since_epoch_;
int32 entry_size_; // Storage size in bytes.
};
COMPILE_ASSERT(sizeof(EntryMetadata) == 8, metadata_size);
static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size");

// This class is not Thread-safe.
class NET_EXPORT_PRIVATE SimpleIndex
Expand Down
2 changes: 1 addition & 1 deletion net/disk_cache/simple/simple_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ImmutableArray {

template <size_t Index>
const T& at() const {
COMPILE_ASSERT(Index < size, array_out_of_bounds);
static_assert(Index < size, "array out of bounds");
return data_[Index];
}

Expand Down
6 changes: 3 additions & 3 deletions net/dns/dns_config_service_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ ConfigParsePosixResult ConvertResStateToDnsConfig(const struct __res_state& res,
dns_config->nameservers.push_back(ipe);
}
#elif defined(OS_LINUX)
COMPILE_ASSERT(arraysize(res.nsaddr_list) >= MAXNS &&
arraysize(res._u._ext.nsaddrs) >= MAXNS,
incompatible_libresolv_res_state);
static_assert(arraysize(res.nsaddr_list) >= MAXNS &&
arraysize(res._u._ext.nsaddrs) >= MAXNS,
"incompatible libresolv res_state");
DCHECK_LE(res.nscount, MAXNS);
// Initially, glibc stores IPv6 in |_ext.nsaddrs| and IPv4 in |nsaddr_list|.
// In res_send.c:res_nsend, it merges |nsaddr_list| into |nsaddrs|,
Expand Down
4 changes: 2 additions & 2 deletions net/dns/dns_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ base::TimeDelta DnsSession::NextTimeoutFromHistogram(unsigned server_index,
int attempt) {
DCHECK_LT(server_index, server_stats_.size());

COMPILE_ASSERT(std::numeric_limits<base::HistogramBase::Count>::is_signed,
histogram_base_count_assumed_to_be_signed);
static_assert(std::numeric_limits<base::HistogramBase::Count>::is_signed,
"histogram base count assumed to be signed");

// Use fixed percentile of observed samples.
const base::SampleVector& samples =
Expand Down
4 changes: 2 additions & 2 deletions net/http/http_auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ const char* HttpAuth::SchemeToString(Scheme scheme) {
"spdyproxy",
"mock",
};
COMPILE_ASSERT(arraysize(kSchemeNames) == AUTH_SCHEME_MAX,
http_auth_scheme_names_incorrect_size);
static_assert(arraysize(kSchemeNames) == AUTH_SCHEME_MAX,
"http auth scheme names incorrect size");
if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) {
NOTREACHED();
return "invalid_scheme";
Expand Down
6 changes: 3 additions & 3 deletions net/http/http_cache_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ HttpCache::Transaction::Transaction(RequestPriority priority, HttpCache* cache)
total_received_bytes_(0),
websocket_handshake_stream_base_create_helper_(NULL),
weak_factory_(this) {
COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders ==
arraysize(kValidationHeaders),
Invalid_number_of_validation_headers);
static_assert(HttpCache::Transaction::kNumValidationHeaders ==
arraysize(kValidationHeaders),
"invalid number of validation headers");

io_callback_ = base::Bind(&Transaction::OnIOComplete,
weak_factory_.GetWeakPtr());
Expand Down
4 changes: 2 additions & 2 deletions net/http/http_network_transaction_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1854,8 +1854,8 @@ TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) {
"HTTP/1.1 301 Moved Permanently",
};

COMPILE_ASSERT(kNumUnreadBodies == arraysize(kStatusLines),
forgot_to_update_kStatusLines);
static_assert(kNumUnreadBodies == arraysize(kStatusLines),
"forgot to update kStatusLines");

for (int i = 0; i < kNumUnreadBodies; ++i)
EXPECT_EQ(kStatusLines[i], response_lines[i]);
Expand Down
6 changes: 3 additions & 3 deletions net/http/http_response_body_drainer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace net {
namespace {

const int kMagicChunkSize = 1024;
COMPILE_ASSERT(
(HttpResponseBodyDrainer::kDrainBodyBufferSize % kMagicChunkSize) == 0,
chunk_size_needs_to_divide_evenly_into_buffer_size);
static_assert((HttpResponseBodyDrainer::kDrainBodyBufferSize %
kMagicChunkSize) == 0,
"chunk size needs to divide evenly into buffer size");

class CloseResultWaiter {
public:
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_security_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace net {

namespace {

COMPILE_ASSERT(kMaxHSTSAgeSecs <= kuint32max, kMaxHSTSAgeSecsTooLarge);
static_assert(kMaxHSTSAgeSecs <= kuint32max, "kMaxHSTSAgeSecs too large");

// MaxAgeToInt converts a string representation of a "whole number" of
// seconds into a uint32. The string may contain an arbitrarily large number,
Expand Down
Loading

0 comments on commit 91e0da9

Please sign in to comment.