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}
diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc
index e8210c9..aed6341 100644
--- a/webrtc/modules/audio_processing/audio_processing_impl.cc
+++ b/webrtc/modules/audio_processing/audio_processing_impl.cc
@@ -791,7 +791,7 @@
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;
diff --git a/webrtc/voice_engine/voe_base_impl.cc b/webrtc/voice_engine/voe_base_impl.cc
index e245fca..7bfaddc 100644
--- a/webrtc/voice_engine/voe_base_impl.cc
+++ b/webrtc/voice_engine/voe_base_impl.cc
@@ -572,7 +572,7 @@
}
int VoEBaseImpl::GetVersion(char version[1024]) {
- assert(kVoiceEngineVersionMaxMessageSize == 1024);
+ static_assert(kVoiceEngineVersionMaxMessageSize == 1024, "");
if (version == nullptr) {
shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError);
diff --git a/webrtc/voice_engine/voe_file_impl.cc b/webrtc/voice_engine/voe_file_impl.cc
index ccf4ec0..78613b0 100644
--- a/webrtc/voice_engine/voe_file_impl.cc
+++ b/webrtc/voice_engine/voe_file_impl.cc
@@ -60,7 +60,7 @@
" 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 @@
"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 @@
"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 @@
"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);
diff --git a/webrtc/voice_engine/voe_hardware_impl.cc b/webrtc/voice_engine/voe_hardware_impl.cc
index 8e9485c..bac0872 100644
--- a/webrtc/voice_engine/voe_hardware_impl.cc
+++ b/webrtc/voice_engine/voe_hardware_impl.cc
@@ -185,8 +185,8 @@
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 @@
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];
diff --git a/webrtc/voice_engine/voe_rtp_rtcp_impl.cc b/webrtc/voice_engine/voe_rtp_rtcp_impl.cc
index 71f3c84..fa15bc8 100644
--- a/webrtc/voice_engine/voe_rtp_rtcp_impl.cc
+++ b/webrtc/voice_engine/voe_rtp_rtcp_impl.cc
@@ -450,7 +450,7 @@
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;