Replace assert() with static_assert() if the condition is evaluatable at

compile time.

The condition of static_assert() is evaluated at compile time which is safer and
more efficient.

Note that static_assert() requires C++11.

The changes were generated by the misc-static-assert ClangTidy check by alexfh@google.com

R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/51019004

Cr-Commit-Position: refs/heads/master@{#9231}
This commit is contained in:
André Susano Pinto 2015-05-20 11:11:07 +02:00
parent 5ca688b3da
commit 664cdafb8a
5 changed files with 11 additions and 11 deletions

View File

@ -791,7 +791,7 @@ int AudioProcessingImpl::delay_offset_ms() const {
int AudioProcessingImpl::StartDebugRecording(
const char filename[AudioProcessing::kMaxFilenameSize]) {
CriticalSectionScoped crit_scoped(crit_);
assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize);
static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, "");
if (filename == NULL) {
return kNullPointerError;

View File

@ -572,7 +572,7 @@ int VoEBaseImpl::StopSend(int channel) {
}
int VoEBaseImpl::GetVersion(char version[1024]) {
assert(kVoiceEngineVersionMaxMessageSize == 1024);
static_assert(kVoiceEngineVersionMaxMessageSize == 1024, "");
if (version == nullptr) {
shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError);

View File

@ -60,7 +60,7 @@ int VoEFileImpl::StartPlayingFileLocally(int channel,
" stopPointMs=%d)",
channel, fileNameUTF8, loop, format, volumeScaling, startPointMs,
stopPointMs);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
@ -152,7 +152,7 @@ int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
"volumeScaling=%5.3f)",
channel, fileNameUTF8, loop, mixWithMicrophone, format,
volumeScaling);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
@ -310,7 +310,7 @@ int VoEFileImpl::StartRecordingPlayout(int channel,
"StartRecordingPlayout(channel=%d, fileNameUTF8=%s, "
"compression, maxSizeBytes=%d)",
channel, fileNameUTF8, maxSizeBytes);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
@ -384,7 +384,7 @@ int VoEFileImpl::StartRecordingMicrophone(const char* fileNameUTF8,
"StartRecordingMicrophone(fileNameUTF8=%s, compression, "
"maxSizeBytes=%d)",
fileNameUTF8, maxSizeBytes);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);

View File

@ -185,8 +185,8 @@ int VoEHardwareImpl::GetRecordingDeviceName(int index,
const uint16_t strLen = 128;
// Check if length has been changed in module
assert(strLen == kAdmMaxDeviceNameSize);
assert(strLen == kAdmMaxGuidSize);
static_assert(strLen == kAdmMaxDeviceNameSize, "");
static_assert(strLen == kAdmMaxGuidSize, "");
char name[strLen];
char guid[strLen];
@ -235,8 +235,8 @@ int VoEHardwareImpl::GetPlayoutDeviceName(int index,
const uint16_t strLen = 128;
// Check if length has been changed in module
assert(strLen == kAdmMaxDeviceNameSize);
assert(strLen == kAdmMaxGuidSize);
static_assert(strLen == kAdmMaxDeviceNameSize, "");
static_assert(strLen == kAdmMaxGuidSize, "");
char name[strLen];
char guid[strLen];

View File

@ -450,7 +450,7 @@ int VoERTP_RTCPImpl::StartRTPDump(int channel,
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"StartRTPDump(channel=%d, fileNameUTF8=%s, direction=%d)",
channel, fileNameUTF8, direction);
assert(1024 == FileWrapper::kMaxFileNameSize);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;