Fix -Wunreachable-code on Linux.

Starting from [1] the toolchain has started to enforce
-Wunreachable-code on Linux, this CL fixes the issues that are preventing
the Chromium roll into WebRTC.

Error example at [2].

[1] - https://chromium-review.googlesource.com/c/chromium/src/+/2093537
[2] - https://ci.chromium.org/p/webrtc/builders/try/linux_rel/34282?

Bug: webrtc:11448
Change-Id: I96e8901ae80c44d69143ed8d972e250b6b926a7d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/171500
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30858}
This commit is contained in:
Mirko Bonadei 2020-03-23 19:53:23 +01:00 committed by Commit Bot
parent 2028a772df
commit f1df04b094
3 changed files with 24 additions and 10 deletions

View File

@ -540,6 +540,7 @@ if (rtc_include_tests) {
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_json",
"../../rtc_base:task_queue_for_test",
"../../rtc_base/system:file_wrapper",
"../../system_wrappers",
"../../test:test_support",
"aec_dump",

View File

@ -16,6 +16,7 @@
#include "modules/audio_processing/test/test_utils.h"
#include "rtc_base/checks.h"
#include "rtc_base/system/file_wrapper.h"
namespace webrtc {
namespace test {
@ -23,13 +24,14 @@ namespace test {
std::vector<WavBasedSimulator::SimulationEventType>
WavBasedSimulator::GetCustomEventChain(const std::string& filename) {
std::vector<WavBasedSimulator::SimulationEventType> call_chain;
FILE* stream = OpenFile(filename.c_str(), "r");
FileWrapper file_wrapper = FileWrapper::OpenReadOnly(filename.c_str());
RTC_CHECK(stream) << "Could not open the custom call order file, reverting "
"to using the default call order";
RTC_CHECK(file_wrapper.is_open())
<< "Could not open the custom call order file, reverting "
"to using the default call order";
char c;
size_t num_read = fread(&c, sizeof(char), 1, stream);
size_t num_read = file_wrapper.Read(&c, sizeof(char));
while (num_read > 0) {
switch (c) {
case 'r':
@ -43,14 +45,12 @@ WavBasedSimulator::GetCustomEventChain(const std::string& filename) {
default:
FATAL() << "Incorrect custom call order file, reverting to using the "
"default call order";
fclose(stream);
return WavBasedSimulator::GetDefaultEventChain();
}
num_read = fread(&c, sizeof(char), 1, stream);
num_read = file_wrapper.Read(&c, sizeof(char));
}
fclose(stream);
return call_chain;
}

View File

@ -391,6 +391,18 @@ class LogCall final {
}
};
// This class is used to explicitly ignore values in the conditional
// logging macros. This avoids compiler warnings like "value computed
// is not used" and "statement has no effect".
class LogMessageVoidify {
public:
LogMessageVoidify() = default;
// This has to be an operator with a precedence lower than << but
// higher than ?:
template <typename... Ts>
void operator&(LogStreamer<Ts...>&& streamer) {}
};
} // namespace webrtc_logging_impl
// Direct use of this class is deprecated; please use the logging macros
@ -660,9 +672,10 @@ inline const char* AdaptString(const std::string& str) {
#define RTC_DLOG_V(sev) RTC_LOG_V(sev)
#define RTC_DLOG_F(sev) RTC_LOG_F(sev)
#else
#define RTC_DLOG_EAT_STREAM_PARAMS() \
while (false) \
::rtc::webrtc_logging_impl::LogStreamer<>()
#define RTC_DLOG_EAT_STREAM_PARAMS() \
while (false) \
::rtc::webrtc_logging_impl::LogMessageVoidify() & \
(::rtc::webrtc_logging_impl::LogStreamer<>())
#define RTC_DLOG(sev) RTC_DLOG_EAT_STREAM_PARAMS()
#define RTC_DLOG_V(sev) RTC_DLOG_EAT_STREAM_PARAMS()
#define RTC_DLOG_F(sev) RTC_DLOG_EAT_STREAM_PARAMS()