diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc index 4a06364d8a..08ff72d7fd 100644 --- a/talk/app/webrtc/java/jni/peerconnection_jni.cc +++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc @@ -78,7 +78,6 @@ #include "third_party/libyuv/include/libyuv/video_common.h" #include "webrtc/base/bind.h" #include "webrtc/base/checks.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/base/logging.h" #include "webrtc/base/messagequeue.h" #include "webrtc/base/ssladapter.h" @@ -249,11 +248,11 @@ static JNIEnv* AttachCurrentThreadIfNeeded() { // because the alternative (of silently passing a 32-bit pointer to a vararg // function expecting a 64-bit param) picks up garbage in the high 32 bits. static jlong jlongFromPointer(void* ptr) { - COMPILE_ASSERT(sizeof(intptr_t) <= sizeof(jlong), - Time_to_rethink_the_use_of_jlongs); + static_assert(sizeof(intptr_t) <= sizeof(jlong), + "Time to rethink the use of jlongs"); // Going through intptr_t to be obvious about the definedness of the // conversion from pointer to integral type. intptr_t to jlong is a standard - // widening by the COMPILE_ASSERT above. + // widening by the static_assert above. jlong ret = reinterpret_cast(ptr); assert(reinterpret_cast(ret) == ptr); return ret; diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index 8baf6de554..3bc10bd674 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -106,7 +106,6 @@ static_library("rtc_base_approved") { sources = [ "checks.cc", "checks.h", - "compile_assert.h", "exp_filter.cc", "exp_filter.h", "md5.cc", diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index d2dc7008e6..a5efdf6222 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -41,7 +41,6 @@ 'sources': [ 'checks.cc', 'checks.h', - 'compile_assert.h', 'exp_filter.cc', 'exp_filter.h', 'md5.cc', diff --git a/webrtc/base/compile_assert.h b/webrtc/base/compile_assert.h deleted file mode 100644 index 47d40a9bd0..0000000000 --- a/webrtc/base/compile_assert.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2013 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// Borrowed from Chromium's src/base/macros.h. - -#ifndef WEBRTC_BASE_COMPILE_ASSERT_H_ -#define WEBRTC_BASE_COMPILE_ASSERT_H_ - -// The COMPILE_ASSERT macro can be used to verify that a compile time -// expression is true. For example, you could use it to verify the -// size of a static array: -// -// COMPILE_ASSERT(ARRAYSIZE_UNSAFE(content_type_names) == CONTENT_NUM_TYPES, -// content_type_names_incorrect_size); -// -// or to make sure a struct is smaller than a certain size: -// -// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); -// -// The second argument to the macro is the name of the variable. If -// the expression is false, most compilers will issue a warning/error -// containing the name of the variable. - -// TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and -// libjingle are merged. -#if !defined(COMPILE_ASSERT) -#if __cplusplus >= 201103L -// Under C++11, just use static_assert. -#define COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) - -#else -template -struct CompileAssert { -}; - -#define COMPILE_ASSERT(expr, msg) \ - typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] - -#endif // __cplusplus >= 201103L -#endif // !defined(COMPILE_ASSERT) - -// Implementation details of COMPILE_ASSERT: -// -// - COMPILE_ASSERT works by defining an array type that has -1 -// elements (and thus is invalid) when the expression is false. -// -// - The simpler definition -// -// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] -// -// does not work, as gcc supports variable-length arrays whose sizes -// are determined at run-time (this is gcc's extension and not part -// of the C++ standard). As a result, gcc fails to reject the -// following code with the simple definition: -// -// int foo; -// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is -// // not a compile-time constant. -// -// - By using the type CompileAssert<(bool(expr))>, we ensures that -// expr is a compile-time constant. (Template arguments must be -// determined at compile-time.) -// -// - The outer parentheses in CompileAssert<(bool(expr))> are necessary -// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written -// -// CompileAssert -// -// instead, these compilers will refuse to compile -// -// COMPILE_ASSERT(5 > 0, some_message); -// -// (They seem to think the ">" in "5 > 0" marks the end of the -// template argument list.) -// -// - The array size is (bool(expr) ? 1 : -1), instead of simply -// -// ((expr) ? 1 : -1). -// -// This is to avoid running into a bug in MS VC 7.1, which -// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. - -#endif // WEBRTC_BASE_COMPILE_ASSERT_H_ diff --git a/webrtc/base/safe_conversions_impl.h b/webrtc/base/safe_conversions_impl.h index 77b053a812..52e52eff82 100644 --- a/webrtc/base/safe_conversions_impl.h +++ b/webrtc/base/safe_conversions_impl.h @@ -15,8 +15,6 @@ #include -#include "webrtc/base/compile_assert.h" - namespace rtc { namespace internal { @@ -177,10 +175,10 @@ struct RangeCheckImpl { template inline RangeCheckResult RangeCheck(Src value) { - COMPILE_ASSERT(std::numeric_limits::is_specialized, - argument_must_be_numeric); - COMPILE_ASSERT(std::numeric_limits::is_specialized, - result_must_be_numeric); + static_assert(std::numeric_limits::is_specialized, + "argument must be numeric"); + static_assert(std::numeric_limits::is_specialized, + "result must be numeric"); return RangeCheckImpl::Check(value); } diff --git a/webrtc/base/scoped_ptr.h b/webrtc/base/scoped_ptr.h index 7a07c9110e..35f4a54ebe 100644 --- a/webrtc/base/scoped_ptr.h +++ b/webrtc/base/scoped_ptr.h @@ -99,7 +99,6 @@ #include // For std::swap(). #include "webrtc/base/common.h" // for ASSERT -#include "webrtc/base/compile_assert.h" // for COMPILE_ASSERT #include "webrtc/base/move.h" // for RTC_MOVE_ONLY_TYPE_FOR_CPP_03 #include "webrtc/base/template_util.h" // for is_convertible, is_array @@ -121,7 +120,7 @@ struct DefaultDeleter { // // Correct implementation should use SFINAE to disable this // constructor. However, since there are no other 1-argument constructors, - // using a COMPILE_ASSERT() based on is_convertible<> and requiring + // using a static_assert based on is_convertible<> and requiring // complete types is simpler and will cause compile failures for equivalent // misuses. // @@ -130,8 +129,8 @@ struct DefaultDeleter { // cannot convert to T*. enum { T_must_be_complete = sizeof(T) }; enum { U_must_be_complete = sizeof(U) }; - COMPILE_ASSERT((rtc::is_convertible::value), - U_ptr_must_implicitly_convert_to_T_ptr); + static_assert(rtc::is_convertible::value, + "U* must implicitly convert to T*"); } inline void operator()(T* ptr) const { enum { type_must_be_complete = sizeof(T) }; @@ -161,7 +160,7 @@ struct DefaultDeleter { template struct DefaultDeleter { // Never allow someone to declare something like scoped_ptr. - COMPILE_ASSERT(sizeof(T) == -1, do_not_use_array_with_size_as_type); + static_assert(sizeof(T) == -1, "do not use array with size as type"); }; // Function object which invokes 'free' on its parameter, which must be @@ -337,7 +336,7 @@ class scoped_ptr { // implementation of scoped_ptr. template scoped_ptr(scoped_ptr other) : impl_(&other.impl_) { - COMPILE_ASSERT(!rtc::is_array::value, U_cannot_be_an_array); + static_assert(!rtc::is_array::value, "U cannot be an array"); } // Constructor. Move constructor for C++03 move emulation of this type. @@ -355,7 +354,7 @@ class scoped_ptr { // scoped_ptr. template scoped_ptr& operator=(scoped_ptr rhs) { - COMPILE_ASSERT(!rtc::is_array::value, U_cannot_be_an_array); + static_assert(!rtc::is_array::value, "U cannot be an array"); impl_.TakeState(&rhs.impl_); return *this; } diff --git a/webrtc/common_audio/resampler/sinc_resampler.cc b/webrtc/common_audio/resampler/sinc_resampler.cc index 352c84cc1e..1f987a416f 100644 --- a/webrtc/common_audio/resampler/sinc_resampler.cc +++ b/webrtc/common_audio/resampler/sinc_resampler.cc @@ -85,7 +85,6 @@ // MSVC++ requires this to be set before any other includes to get M_PI. #define _USE_MATH_DEFINES -#include "webrtc/base/compile_assert.h" #include "webrtc/common_audio/resampler/sinc_resampler.h" #include "webrtc/system_wrappers/interface/cpu_features_wrapper.h" #include "webrtc/typedefs.h" diff --git a/webrtc/common_audio/wav_file_unittest.cc b/webrtc/common_audio/wav_file_unittest.cc index 1991c3b59b..78b0a34de9 100644 --- a/webrtc/common_audio/wav_file_unittest.cc +++ b/webrtc/common_audio/wav_file_unittest.cc @@ -15,7 +15,6 @@ #include #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/common_audio/wav_header.h" #include "webrtc/common_audio/wav_file.h" #include "webrtc/test/testsupport/fileutils.h" @@ -67,7 +66,7 @@ TEST(WavWriterTest, CPP) { }; static const int kContentSize = kWavHeaderSize + kNumSamples * sizeof(int16_t) + sizeof(kMetadata); - COMPILE_ASSERT(sizeof(kExpectedContents) == kContentSize, content_size); + static_assert(sizeof(kExpectedContents) == kContentSize, "content size"); EXPECT_EQ(size_t(kContentSize), test::GetFileSize(outfile)); FILE* f = fopen(outfile.c_str(), "rb"); ASSERT_TRUE(f); @@ -123,7 +122,7 @@ TEST(WavWriterTest, C) { }; static const int kContentSize = kWavHeaderSize + kNumSamples * sizeof(int16_t); - COMPILE_ASSERT(sizeof(kExpectedContents) == kContentSize, content_size); + static_assert(sizeof(kExpectedContents) == kContentSize, "content size"); EXPECT_EQ(size_t(kContentSize), test::GetFileSize(outfile)); FILE* f = fopen(outfile.c_str(), "rb"); ASSERT_TRUE(f); diff --git a/webrtc/common_audio/wav_header.cc b/webrtc/common_audio/wav_header.cc index 9776bc4d1d..fefbee0507 100644 --- a/webrtc/common_audio/wav_header.cc +++ b/webrtc/common_audio/wav_header.cc @@ -29,7 +29,7 @@ struct ChunkHeader { uint32_t ID; uint32_t Size; }; -COMPILE_ASSERT(sizeof(ChunkHeader) == 8, chunk_header_size); +static_assert(sizeof(ChunkHeader) == 8, "ChunkHeader size"); // We can't nest this definition in WavHeader, because VS2013 gives an error // on sizeof(WavHeader::fmt): "error C2070: 'unknown': illegal sizeof operand". @@ -42,7 +42,7 @@ struct FmtSubchunk { uint16_t BlockAlign; uint16_t BitsPerSample; }; -COMPILE_ASSERT(sizeof(FmtSubchunk) == 24, fmt_subchunk_size); +static_assert(sizeof(FmtSubchunk) == 24, "FmtSubchunk size"); const uint32_t kFmtSubchunkSize = sizeof(FmtSubchunk) - sizeof(ChunkHeader); struct WavHeader { @@ -55,7 +55,7 @@ struct WavHeader { ChunkHeader header; } data; }; -COMPILE_ASSERT(sizeof(WavHeader) == kWavHeaderSize, no_padding_in_header); +static_assert(sizeof(WavHeader) == kWavHeaderSize, "no padding in header"); } // namespace diff --git a/webrtc/common_audio/wav_header_unittest.cc b/webrtc/common_audio/wav_header_unittest.cc index 546cc1e44c..e03cb303aa 100644 --- a/webrtc/common_audio/wav_header_unittest.cc +++ b/webrtc/common_audio/wav_header_unittest.cc @@ -11,7 +11,6 @@ #include #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/common_audio/wav_header.h" namespace webrtc { @@ -266,7 +265,7 @@ TEST(WavHeaderTest, WriteAndReadWavHeader) { 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 0xa4, 0xa4, 0xa4, 0xa4, // untouched bytes after header }; - COMPILE_ASSERT(sizeof(kExpectedBuf) == kSize, buf_size); + static_assert(sizeof(kExpectedBuf) == kSize, "buffer size"); EXPECT_EQ(0, memcmp(kExpectedBuf, buf, kSize)); int num_channels = 0; diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest.cc index 7e3494b178..6c7b97f822 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest.cc @@ -13,7 +13,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/checks.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/base/md5digest.h" #include "webrtc/base/thread_annotations.h" #include "webrtc/modules/audio_coding/main/acm2/acm_receive_test.h" @@ -133,8 +132,8 @@ class AudioCodingModuleTest : public ::testing::Test { input_frame_.sample_rate_hz_ = kSampleRateHz; input_frame_.num_channels_ = 1; input_frame_.samples_per_channel_ = kSampleRateHz * 10 / 1000; // 10 ms. - COMPILE_ASSERT(kSampleRateHz * 10 / 1000 <= AudioFrame::kMaxDataSizeSamples, - audio_frame_too_small); + static_assert(kSampleRateHz * 10 / 1000 <= AudioFrame::kMaxDataSizeSamples, + "audio frame too small"); memset(input_frame_.data_, 0, input_frame_.samples_per_channel_ * sizeof(input_frame_.data_[0])); @@ -461,7 +460,7 @@ class AcmIsacMtTest : public AudioCodingModuleMtTest { } virtual void RegisterCodec() OVERRIDE { - COMPILE_ASSERT(kSampleRateHz == 16000, test_designed_for_isac_16khz); + static_assert(kSampleRateHz == 16000, "test designed for iSAC 16 kHz"); // Register iSAC codec in ACM, effectively unregistering the PCM16B codec // registered in AudioCodingModuleTest::SetUp(); diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc index b8f12af061..d5f893a4b5 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc @@ -12,7 +12,6 @@ #include #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/base/md5digest.h" #include "webrtc/base/thread_annotations.h" #include "webrtc/modules/audio_coding/main/acm2/acm_receive_test_oldapi.h" @@ -137,8 +136,8 @@ class AudioCodingModuleTestOldApi : public ::testing::Test { input_frame_.sample_rate_hz_ = kSampleRateHz; input_frame_.num_channels_ = 1; input_frame_.samples_per_channel_ = kSampleRateHz * 10 / 1000; // 10 ms. - COMPILE_ASSERT(kSampleRateHz * 10 / 1000 <= AudioFrame::kMaxDataSizeSamples, - audio_frame_too_small); + static_assert(kSampleRateHz * 10 / 1000 <= AudioFrame::kMaxDataSizeSamples, + "audio frame too small"); memset(input_frame_.data_, 0, input_frame_.samples_per_channel_ * sizeof(input_frame_.data_[0])); @@ -463,7 +462,7 @@ class AcmIsacMtTestOldApi : public AudioCodingModuleMtTestOldApi { } virtual void RegisterCodec() { - COMPILE_ASSERT(kSampleRateHz == 16000, test_designed_for_isac_16khz); + static_assert(kSampleRateHz == 16000, "test designed for iSAC 16 kHz"); AudioCodingModule::Codec("ISAC", &codec_, kSampleRateHz, 1); codec_.pltype = kPayloadType; diff --git a/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc index 5ed528d091..579c0badd4 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc @@ -15,7 +15,6 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/audio_coding/neteq/interface/neteq.h" #include "webrtc/modules/audio_coding/neteq/mock/mock_external_decoder_pcm16b.h" #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" @@ -360,11 +359,11 @@ TEST_F(LargeTimestampJumpTest, JumpLongerThanHalfRange) { static const uint32_t kStartTimestamp = 2880; static const uint32_t kJumpFromTimestamp = 7200; static const uint32_t kJumpToTimestamp = 2869342376; - COMPILE_ASSERT(kJumpFromTimestamp < kJumpToTimestamp, - timestamp_jump_should_not_result_in_wrap); - COMPILE_ASSERT( + static_assert(kJumpFromTimestamp < kJumpToTimestamp, + "timestamp jump should not result in wrap"); + static_assert( static_cast(kJumpToTimestamp - kJumpFromTimestamp) > 0x7FFFFFFF, - jump_should_be_larger_than_half_range); + "jump should be larger than half range"); // Replace the default RTP generator with one that jumps in timestamp. rtp_generator_.reset(new test::TimestampJumpRtpGenerator(samples_per_ms_, kStartSeqeunceNumber, @@ -384,11 +383,11 @@ TEST_F(LargeTimestampJumpTest, JumpLongerThanHalfRangeAndWrap) { static const uint32_t kStartTimestamp = 3221223116; static const uint32_t kJumpFromTimestamp = 3221223216; static const uint32_t kJumpToTimestamp = 1073744278; - COMPILE_ASSERT(kJumpToTimestamp < kJumpFromTimestamp, - timestamp_jump_should_result_in_wrap); - COMPILE_ASSERT( + static_assert(kJumpToTimestamp < kJumpFromTimestamp, + "timestamp jump should result in wrap"); + static_assert( static_cast(kJumpToTimestamp - kJumpFromTimestamp) > 0x7FFFFFFF, - jump_should_be_larger_than_half_range); + "jump should be larger than half range"); // Replace the default RTP generator with one that jumps in timestamp. rtp_generator_.reset(new test::TimestampJumpRtpGenerator(samples_per_ms_, kStartSeqeunceNumber, @@ -443,11 +442,11 @@ TEST_F(ShortTimestampJumpTest, JumpShorterThanHalfRange) { static const uint32_t kStartTimestamp = 4711; static const uint32_t kJumpFromTimestamp = 4811; static const uint32_t kJumpToTimestamp = 2147483747; - COMPILE_ASSERT(kJumpFromTimestamp < kJumpToTimestamp, - timestamp_jump_should_not_result_in_wrap); - COMPILE_ASSERT( + static_assert(kJumpFromTimestamp < kJumpToTimestamp, + "timestamp jump should not result in wrap"); + static_assert( static_cast(kJumpToTimestamp - kJumpFromTimestamp) < 0x7FFFFFFF, - jump_should_be_smaller_than_half_range); + "jump should be smaller than half range"); // Replace the default RTP generator with one that jumps in timestamp. rtp_generator_.reset(new test::TimestampJumpRtpGenerator(samples_per_ms_, kStartSeqeunceNumber, @@ -467,11 +466,11 @@ TEST_F(ShortTimestampJumpTest, JumpShorterThanHalfRangeAndWrap) { static const uint32_t kStartTimestamp = 3221227827; static const uint32_t kJumpFromTimestamp = 3221227927; static const uint32_t kJumpToTimestamp = 1073739567; - COMPILE_ASSERT(kJumpToTimestamp < kJumpFromTimestamp, - timestamp_jump_should_result_in_wrap); - COMPILE_ASSERT( + static_assert(kJumpToTimestamp < kJumpFromTimestamp, + "timestamp jump should result in wrap"); + static_assert( static_cast(kJumpToTimestamp - kJumpFromTimestamp) < 0x7FFFFFFF, - jump_should_be_smaller_than_half_range); + "jump should be smaller than half range"); // Replace the default RTP generator with one that jumps in timestamp. rtp_generator_.reset(new test::TimestampJumpRtpGenerator(samples_per_ms_, kStartSeqeunceNumber, diff --git a/webrtc/modules/audio_coding/neteq/tools/audio_checksum.h b/webrtc/modules/audio_coding/neteq/tools/audio_checksum.h index 6070eff61c..173713a3be 100644 --- a/webrtc/modules/audio_coding/neteq/tools/audio_checksum.h +++ b/webrtc/modules/audio_coding/neteq/tools/audio_checksum.h @@ -13,7 +13,6 @@ #include -#include "webrtc/base/compile_assert.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/md5digest.h" #include "webrtc/base/stringencode.h" diff --git a/webrtc/modules/audio_processing/agc/agc.cc b/webrtc/modules/audio_processing/agc/agc.cc index 8c2e1c3cc4..dda1636d03 100644 --- a/webrtc/modules/audio_processing/agc/agc.cc +++ b/webrtc/modules/audio_processing/agc/agc.cc @@ -15,7 +15,6 @@ #include -#include "webrtc/base/compile_assert.h" #include "webrtc/common_audio/resampler/include/resampler.h" #include "webrtc/modules/audio_processing/agc/agc_audio_proc.h" #include "webrtc/modules/audio_processing/agc/common.h" @@ -99,8 +98,8 @@ int Agc::Process(const int16_t* audio, int length, int sample_rate_hz) { // Initialize to 0.5 which is a neutral value for combining probabilities, // in case the standalone-VAD is not enabled. double p_combined[] = {0.5, 0.5, 0.5, 0.5}; - COMPILE_ASSERT(sizeof(p_combined) / sizeof(p_combined[0]) == kMaxNumFrames, - combined_probability_incorrect_size); + static_assert(sizeof(p_combined) / sizeof(p_combined[0]) == kMaxNumFrames, + "combined probability incorrect size"); if (standalone_vad_enabled_) { if (standalone_vad_->GetActivity(p_combined, kMaxNumFrames) < 0) return -1; diff --git a/webrtc/modules/audio_processing/agc/agc_audio_proc.cc b/webrtc/modules/audio_processing/agc/agc_audio_proc.cc index bdefdf420a..ccc77cc9ea 100644 --- a/webrtc/modules/audio_processing/agc/agc_audio_proc.cc +++ b/webrtc/modules/audio_processing/agc/agc_audio_proc.cc @@ -13,7 +13,6 @@ #include #include -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h" #include "webrtc/modules/audio_processing/agc/pitch_internal.h" #include "webrtc/modules/audio_processing/agc/pole_zero_filter.h" @@ -47,11 +46,11 @@ AgcAudioProc::AgcAudioProc() pre_filter_handle_(new PreFiltBankstr), high_pass_filter_(PoleZeroFilter::Create( kCoeffNumerator, kFilterOrder, kCoeffDenominator, kFilterOrder)) { - COMPILE_ASSERT(kNumPastSignalSamples + kNumSubframeSamples == - sizeof(kLpcAnalWin) / sizeof(kLpcAnalWin[0]), - lpc_analysis_window_incorrect_size); - COMPILE_ASSERT(kLpcOrder + 1 == sizeof(kCorrWeight) / sizeof(kCorrWeight[0]), - correlation_weight_incorrect_size); + static_assert(kNumPastSignalSamples + kNumSubframeSamples == + sizeof(kLpcAnalWin) / sizeof(kLpcAnalWin[0]), + "lpc analysis window incorrect size"); + static_assert(kLpcOrder + 1 == sizeof(kCorrWeight) / sizeof(kCorrWeight[0]), + "correlation weight incorrect size"); // TODO(turajs): Are we doing too much in the constructor? float data[kDftSize]; diff --git a/webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h b/webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h index 24ba741456..f3b7fd1e93 100644 --- a/webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h +++ b/webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h @@ -11,8 +11,6 @@ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_AUDIO_PROC_INTERNAL_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_AUDIO_PROC_INTERNAL_H_ -#include "webrtc/base/compile_assert.h" - namespace webrtc { // These values should match MATLAB counterparts for unit-tests to pass. @@ -71,10 +69,12 @@ static const float kCoeffNumerator[kFilterOrder + 1] = {0.974827f, -1.949650f, static const float kCoeffDenominator[kFilterOrder + 1] = {1.0f, -1.971999f, 0.972457f}; -COMPILE_ASSERT(kFilterOrder + 1 == sizeof(kCoeffNumerator) / - sizeof(kCoeffNumerator[0]), numerator_coefficients_incorrect_size); -COMPILE_ASSERT(kFilterOrder + 1 == sizeof(kCoeffDenominator) / - sizeof(kCoeffDenominator[0]), denominator_coefficients_incorrect_size); +static_assert(kFilterOrder + 1 == + sizeof(kCoeffNumerator) / sizeof(kCoeffNumerator[0]), + "numerator coefficients incorrect size"); +static_assert(kFilterOrder + 1 == + sizeof(kCoeffDenominator) / sizeof(kCoeffDenominator[0]), + "denominator coefficients incorrect size"); } // namespace webrtc diff --git a/webrtc/modules/audio_processing/agc/agc_manager_direct.cc b/webrtc/modules/audio_processing/agc/agc_manager_direct.cc index 99f45090a0..24fbd56eb2 100644 --- a/webrtc/modules/audio_processing/agc/agc_manager_direct.cc +++ b/webrtc/modules/audio_processing/agc/agc_manager_direct.cc @@ -17,7 +17,6 @@ #include #endif -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/audio_processing/agc/gain_map_internal.h" #include "webrtc/modules/audio_processing/gain_control_impl.h" #include "webrtc/modules/interface/module_common_types.h" @@ -47,7 +46,7 @@ const int kMinCompressionGain = 2; const float kCompressionGainStep = 0.05f; const int kMaxMicLevel = 255; -COMPILE_ASSERT(kGainMapSize > kMaxMicLevel, gain_map_too_small); +static_assert(kGainMapSize > kMaxMicLevel, "gain map too small"); const int kMinMicLevel = 12; const int kMinInitMicLevel = 85; diff --git a/webrtc/modules/audio_processing/agc/histogram.cc b/webrtc/modules/audio_processing/agc/histogram.cc index fa511b695e..1d3035fe12 100644 --- a/webrtc/modules/audio_processing/agc/histogram.cc +++ b/webrtc/modules/audio_processing/agc/histogram.cc @@ -13,7 +13,6 @@ #include #include -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/interface/module_common_types.h" namespace webrtc { @@ -69,8 +68,9 @@ Histogram::Histogram() buffer_is_full_(false), len_circular_buffer_(0), len_high_activity_(0) { - COMPILE_ASSERT(kHistSize == sizeof(kHistBinCenters) / - sizeof(kHistBinCenters[0]), histogram_bin_centers_incorrect_size); + static_assert( + kHistSize == sizeof(kHistBinCenters) / sizeof(kHistBinCenters[0]), + "histogram bin centers incorrect size"); } Histogram::Histogram(int window_size) diff --git a/webrtc/modules/audio_processing/agc/pitch_based_vad.cc b/webrtc/modules/audio_processing/agc/pitch_based_vad.cc index bbbc40775d..0cfa52a010 100644 --- a/webrtc/modules/audio_processing/agc/pitch_based_vad.cc +++ b/webrtc/modules/audio_processing/agc/pitch_based_vad.cc @@ -14,7 +14,6 @@ #include #include -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/audio_processing/agc/circular_buffer.h" #include "webrtc/modules/audio_processing/agc/common.h" #include "webrtc/modules/audio_processing/agc/noise_gmm_tables.h" @@ -23,8 +22,8 @@ namespace webrtc { -COMPILE_ASSERT(kNoiseGmmDim == kVoiceGmmDim, - noise_and_voice_gmm_dimension_not_equal); +static_assert(kNoiseGmmDim == kVoiceGmmDim, + "noise and voice gmm dimension not equal"); // These values should match MATLAB counterparts for unit-tests to pass. static const int kPosteriorHistorySize = 500; // 5 sec of 10 ms frames. diff --git a/webrtc/modules/audio_processing/agc/pole_zero_filter_unittest.cc b/webrtc/modules/audio_processing/agc/pole_zero_filter_unittest.cc index 29837e79b2..9828490fe9 100644 --- a/webrtc/modules/audio_processing/agc/pole_zero_filter_unittest.cc +++ b/webrtc/modules/audio_processing/agc/pole_zero_filter_unittest.cc @@ -14,7 +14,6 @@ #include #include "gtest/gtest.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/audio_processing/agc/agc_audio_proc_internal.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/test/testsupport/fileutils.h" diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc index 92e63f19b8..5d7de3a1fe 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc @@ -12,7 +12,6 @@ #include -#include "webrtc/base/compile_assert.h" #include "webrtc/base/platform_file.h" #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" @@ -55,7 +54,7 @@ namespace webrtc { // Throughout webrtc, it's assumed that success is represented by zero. -COMPILE_ASSERT(AudioProcessing::kNoError == 0, no_error_must_be_zero); +static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); // This class has two main functionalities: // diff --git a/webrtc/modules/audio_processing/transient/file_utils.h b/webrtc/modules/audio_processing/transient/file_utils.h index 8dc477de5e..dbc3b5f788 100644 --- a/webrtc/modules/audio_processing/transient/file_utils.h +++ b/webrtc/modules/audio_processing/transient/file_utils.h @@ -13,7 +13,6 @@ #include -#include "webrtc/base/compile_assert.h" #include "webrtc/system_wrappers/interface/file_wrapper.h" #include "webrtc/typedefs.h" @@ -24,8 +23,8 @@ namespace webrtc { template inline Dest bit_cast(const Source& source) { // A compile error here means your Dest and Source have different sizes. - COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), - dest_and_source_have_different_sizes); + static_assert(sizeof(Dest) == sizeof(Source), + "Dest and Source have different sizes"); Dest dest; memcpy(&dest, &source, sizeof(dest)); diff --git a/webrtc/modules/desktop_capture/win/cursor.cc b/webrtc/modules/desktop_capture/win/cursor.cc index 53a90e5860..2e108f6998 100644 --- a/webrtc/modules/desktop_capture/win/cursor.cc +++ b/webrtc/modules/desktop_capture/win/cursor.cc @@ -12,7 +12,6 @@ #include -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/desktop_capture/win/scoped_gdi_object.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/desktop_geometry.h" @@ -78,8 +77,8 @@ void AddCursorOutline(int width, int height, uint32_t* data) { // Premultiplies RGB components of the pixel data in the given image by // the corresponding alpha components. void AlphaMul(uint32_t* data, int width, int height) { - COMPILE_ASSERT(sizeof(uint32_t) == kBytesPerPixel, - size_of_uint32_should_be_the_bytes_per_pixel); + static_assert(sizeof(uint32_t) == kBytesPerPixel, + "size of uint32 should be the number of bytes per pixel"); for (uint32_t* data_end = data + width * height; data != data_end; ++data) { RGBQUAD* from = reinterpret_cast(data); diff --git a/webrtc/modules/media_file/source/media_file_unittest.cc b/webrtc/modules/media_file/source/media_file_unittest.cc index dc70b2baeb..ea6b953d93 100644 --- a/webrtc/modules/media_file/source/media_file_unittest.cc +++ b/webrtc/modules/media_file/source/media_file_unittest.cc @@ -9,7 +9,6 @@ */ #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/media_file/interface/media_file.h" #include "webrtc/system_wrappers/interface/sleep.h" #include "webrtc/test/testsupport/fileutils.h" @@ -78,7 +77,7 @@ TEST_F(MediaFileTest, WriteWavFile) { 'd', 'a', 't', 'a', 0x40, 0x1, 0, 0, // size of payload: 320 }; - COMPILE_ASSERT(sizeof(kExpectedHeader) == kHeaderSize, header_size); + static_assert(sizeof(kExpectedHeader) == kHeaderSize, "header size"); EXPECT_EQ(kHeaderSize + kPayloadSize, webrtc::test::GetFileSize(outfile)); FILE* f = fopen(outfile.c_str(), "rb"); diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc index 1412bdf6e2..5cde808fdb 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc @@ -14,14 +14,13 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/compile_assert.h" #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h" #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h" #include "webrtc/typedefs.h" -#define CHECK_ARRAY_SIZE(expected_size, array) \ - COMPILE_ASSERT(expected_size == sizeof(array) / sizeof(array[0]), \ - check_array_size); +#define CHECK_ARRAY_SIZE(expected_size, array) \ + static_assert(expected_size == sizeof(array) / sizeof(array[0]), \ + "check array size"); namespace webrtc { namespace { diff --git a/webrtc/overrides/webrtc/base/logging.cc b/webrtc/overrides/webrtc/base/logging.cc index a2ffba650b..18883313f6 100644 --- a/webrtc/overrides/webrtc/base/logging.cc +++ b/webrtc/overrides/webrtc/base/logging.cc @@ -40,8 +40,8 @@ void (*g_logging_delegate_function)(const std::string&) = NULL; void (*g_extra_logging_init_function)( void (*logging_delegate_function)(const std::string&)) = NULL; #ifndef NDEBUG -COMPILE_ASSERT(sizeof(base::subtle::Atomic32) == sizeof(base::PlatformThreadId), - atomic32_not_same_size_as_platformthreadid); +static_assert(sizeof(base::subtle::Atomic32) == sizeof(base::PlatformThreadId), + "Atomic32 not same size as PlatformThreadId"); base::subtle::Atomic32 g_init_logging_delegate_thread_id = 0; #endif diff --git a/webrtc/system_wrappers/interface/compile_assert_c.h b/webrtc/system_wrappers/interface/compile_assert_c.h index d9ba86600c..dbb5292d97 100644 --- a/webrtc/system_wrappers/interface/compile_assert_c.h +++ b/webrtc/system_wrappers/interface/compile_assert_c.h @@ -11,8 +11,10 @@ #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ -// Only use this for C files. For C++, use compile_assert.h. -// +#ifdef __cplusplus +#error "Only use this for C files. For C++, use static_assert." +#endif + // Use this macro to verify at compile time that certain restrictions are met. // The argument is the boolean expression to evaluate. // Example: diff --git a/webrtc/system_wrappers/interface/scoped_ptr.h b/webrtc/system_wrappers/interface/scoped_ptr.h index 90c7b8b268..974fcdf270 100644 --- a/webrtc/system_wrappers/interface/scoped_ptr.h +++ b/webrtc/system_wrappers/interface/scoped_ptr.h @@ -104,7 +104,6 @@ #include // For std::swap(). -#include "webrtc/base/compile_assert.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/move.h" #include "webrtc/base/template_util.h" @@ -124,7 +123,7 @@ struct DefaultDeleter { // // Correct implementation should use SFINAE to disable this // constructor. However, since there are no other 1-argument constructors, - // using a COMPILE_ASSERT() based on is_convertible<> and requiring + // using a static_assert based on is_convertible<> and requiring // complete types is simpler and will cause compile failures for equivalent // misuses. // @@ -133,8 +132,8 @@ struct DefaultDeleter { // cannot convert to T*. enum { T_must_be_complete = sizeof(T) }; enum { U_must_be_complete = sizeof(U) }; - COMPILE_ASSERT((rtc::is_convertible::value), - U_ptr_must_implicitly_convert_to_T_ptr); + static_assert(rtc::is_convertible::value, + "U* must implicitly convert to T*"); } inline void operator()(T* ptr) const { enum { type_must_be_complete = sizeof(T) }; @@ -164,7 +163,7 @@ struct DefaultDeleter { template struct DefaultDeleter { // Never allow someone to declare something like scoped_ptr. - COMPILE_ASSERT(sizeof(T) == -1, do_not_use_array_with_size_as_type); + static_assert(sizeof(T) == -1, "do not use array with size as type"); }; // Function object which invokes 'free' on its parameter, which must be @@ -318,8 +317,8 @@ class scoped_ptr { // TODO(ajm): If we ever import RefCountedBase, this check needs to be // enabled. - //COMPILE_ASSERT(webrtc::internal::IsNotRefCounted::value, - // T_is_refcounted_type_and_needs_scoped_refptr); + //static_assert(webrtc::internal::IsNotRefCounted::value, + // "T is refcounted type and needs scoped refptr"); public: // The element and deleter types. @@ -351,7 +350,7 @@ class scoped_ptr { template scoped_ptr(scoped_ptr&& other) : impl_(&other.impl_) { - COMPILE_ASSERT(!rtc::is_array::value, U_cannot_be_an_array); + static_assert(!rtc::is_array::value, "U cannot be an array"); } // operator=. Allows assignment from a scoped_ptr rvalue for a convertible @@ -366,7 +365,7 @@ class scoped_ptr { // scoped_ptr. template scoped_ptr& operator=(scoped_ptr&& rhs) { - COMPILE_ASSERT(!rtc::is_array::value, U_cannot_be_an_array); + static_assert(!rtc::is_array::value, "U cannot be an array"); impl_.TakeState(&rhs.impl_); return *this; } diff --git a/webrtc/system_wrappers/source/atomic32_win.cc b/webrtc/system_wrappers/source/atomic32_win.cc index 50c49895d4..f3c10f6b7c 100644 --- a/webrtc/system_wrappers/source/atomic32_win.cc +++ b/webrtc/system_wrappers/source/atomic32_win.cc @@ -13,15 +13,14 @@ #include #include -#include "webrtc/base/compile_assert.h" #include "webrtc/common_types.h" namespace webrtc { Atomic32::Atomic32(int32_t initial_value) : value_(initial_value) { - COMPILE_ASSERT(sizeof(value_) == sizeof(LONG), - counter_variable_is_the_expected_size); + static_assert(sizeof(value_) == sizeof(LONG), + "counter variable is the expected size"); assert(Is32bitAligned()); }