diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn index 4ed6377eea..c9c5ff1328 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -1080,6 +1080,7 @@ rtc_static_library("neteq") { "../../rtc_base:gtest_prod", "../../rtc_base:rtc_base_approved", "../../rtc_base:sanitizer", + "../../rtc_base/system:fallthrough", "../../system_wrappers:field_trial_api", "../../system_wrappers:metrics_api", ] diff --git a/modules/audio_coding/neteq/neteq_impl.cc b/modules/audio_coding/neteq/neteq_impl.cc index 85e3690c9d..b107626439 100644 --- a/modules/audio_coding/neteq/neteq_impl.cc +++ b/modules/audio_coding/neteq/neteq_impl.cc @@ -46,6 +46,7 @@ #include "rtc_base/logging.h" #include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/sanitizer.h" +#include "rtc_base/system/fallthrough.h" #include "rtc_base/trace_event.h" #include "system_wrappers/include/field_trial.h" @@ -943,7 +944,7 @@ int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame, bool* muted) { static_cast(output_size_samples_)); // Skipping break on purpose. Execution should move on into the // next case. - FALLTHROUGH(); + RTC_FALLTHROUGH(); } case kAudioRepetition: { // TODO(hlundin): Write test for this. diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn index fd0f937217..3efab79bcf 100644 --- a/modules/audio_device/BUILD.gn +++ b/modules/audio_device/BUILD.gn @@ -82,6 +82,7 @@ if (rtc_include_internal_audio_device && is_ios) { "../../rtc_base:checks", "../../rtc_base:gtest_prod", "../../rtc_base:rtc_base", + "../../rtc_base/system:fallthrough", "../../sdk:audio_objc", "../../sdk:common_objc", "../../system_wrappers:metrics_api", diff --git a/modules/audio_device/ios/voice_processing_audio_unit.mm b/modules/audio_device/ios/voice_processing_audio_unit.mm index c350969335..48bd7e117a 100644 --- a/modules/audio_device/ios/voice_processing_audio_unit.mm +++ b/modules/audio_device/ios/voice_processing_audio_unit.mm @@ -11,6 +11,7 @@ #import "modules/audio_device/ios/voice_processing_audio_unit.h" #include "rtc_base/checks.h" +#include "rtc_base/system/fallthrough.h" #include "system_wrappers/include/metrics.h" #import "WebRTC/RTCLogging.h" @@ -444,12 +445,12 @@ void VoiceProcessingAudioUnit::DisposeAudioUnit() { case kStarted: Stop(); // Fall through. - FALLTHROUGH(); + RTC_FALLTHROUGH(); case kInitialized: Uninitialize(); break; case kUninitialized: - FALLTHROUGH(); + RTC_FALLTHROUGH(); case kInitRequired: break; } diff --git a/modules/remote_bitrate_estimator/BUILD.gn b/modules/remote_bitrate_estimator/BUILD.gn index 1c9504387d..ddd77d1d8c 100644 --- a/modules/remote_bitrate_estimator/BUILD.gn +++ b/modules/remote_bitrate_estimator/BUILD.gn @@ -142,6 +142,7 @@ if (rtc_include_tests) { "../../rtc_base:rtc_base_approved", "../../rtc_base:rtc_numerics", "../../rtc_base/experiments:alr_experiment", + "../../rtc_base/system:fallthrough", "../../system_wrappers", "../../system_wrappers:field_trial_api", "../../test:perf_test", diff --git a/modules/remote_bitrate_estimator/test/bwe.cc b/modules/remote_bitrate_estimator/test/bwe.cc index cf72f29d24..656cb5b4cf 100644 --- a/modules/remote_bitrate_estimator/test/bwe.cc +++ b/modules/remote_bitrate_estimator/test/bwe.cc @@ -18,6 +18,7 @@ #include "modules/remote_bitrate_estimator/test/estimators/send_side.h" #include "modules/remote_bitrate_estimator/test/estimators/tcp.h" #include "rtc_base/constructormagic.h" +#include "rtc_base/system/fallthrough.h" namespace webrtc { namespace testing { @@ -97,7 +98,7 @@ BweSender* CreateBweSender(BandwidthEstimatorType estimator, case kBbrEstimator: return new BbrBweSender(observer, clock); case kTcpEstimator: - FALLTHROUGH(); + RTC_FALLTHROUGH(); case kNullEstimator: return new NullBweSender(); } diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index 7180d50f84..24f3b7596e 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -212,6 +212,7 @@ rtc_static_library("rtp_rtcp") { "../../rtc_base:rtc_numerics", "../../rtc_base:sequenced_task_checker", "../../rtc_base:stringutils", + "../../rtc_base/system:fallthrough", "../../system_wrappers", "../../system_wrappers:field_trial_api", "../../system_wrappers:metrics_api", diff --git a/modules/rtp_rtcp/source/rtp_format_h264.cc b/modules/rtp_rtcp/source/rtp_format_h264.cc index 57a79557e9..226cc36656 100644 --- a/modules/rtp_rtcp/source/rtp_format_h264.cc +++ b/modules/rtp_rtcp/source/rtp_format_h264.cc @@ -24,6 +24,7 @@ #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" +#include "rtc_base/system/fallthrough.h" #include "system_wrappers/include/metrics.h" namespace webrtc { @@ -574,7 +575,7 @@ bool RtpDepacketizerH264::ProcessStapAOrSingleNalu( } case H264::NaluType::kIdr: parsed_payload->frame_type = kVideoFrameKey; - FALLTHROUGH(); + RTC_FALLTHROUGH(); case H264::NaluType::kSlice: { rtc::Optional pps_id = PpsParser::ParsePpsIdFromSlice( &payload_data[start_offset], end_offset - start_offset); diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn index b337d7184a..16717b4f42 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -122,6 +122,7 @@ rtc_static_library("video_coding") { "../../rtc_base:rtc_task_queue", "../../rtc_base:sequenced_task_checker", "../../rtc_base/experiments:alr_experiment", + "../../rtc_base/system:fallthrough", "../../system_wrappers", "../../system_wrappers:field_trial_api", "../../system_wrappers:metrics_api", diff --git a/modules/video_coding/jitter_buffer.cc b/modules/video_coding/jitter_buffer.cc index aefe6aee5f..079780cadb 100644 --- a/modules/video_coding/jitter_buffer.cc +++ b/modules/video_coding/jitter_buffer.cc @@ -25,6 +25,7 @@ #include "modules/video_coding/packet.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" +#include "rtc_base/system/fallthrough.h" #include "rtc_base/trace_event.h" #include "system_wrappers/include/clock.h" #include "system_wrappers/include/event_wrapper.h" @@ -749,7 +750,7 @@ VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(const VCMPacket& packet, frame_event_->Set(); } } - FALLTHROUGH(); + RTC_FALLTHROUGH(); } // Note: There is no break here - continuing to kDecodableSession. case kDecodableSession: { diff --git a/modules/video_coding/rtp_frame_reference_finder.cc b/modules/video_coding/rtp_frame_reference_finder.cc index 512d6f26f4..79f11cd8a4 100644 --- a/modules/video_coding/rtp_frame_reference_finder.cc +++ b/modules/video_coding/rtp_frame_reference_finder.cc @@ -17,6 +17,7 @@ #include "modules/video_coding/packet_buffer.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" +#include "rtc_base/system/fallthrough.h" namespace webrtc { namespace video_coding { @@ -71,7 +72,7 @@ void RtpFrameReferenceFinder::RetryStashedFrames() { case kHandOff: complete_frame = true; frame_callback_->OnCompleteFrame(std::move(*frame_it)); - FALLTHROUGH(); + RTC_FALLTHROUGH(); case kDrop: frame_it = stashed_frames_.erase(frame_it); } diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index f0e2fd79cf..4d5b9d62a9 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -879,6 +879,7 @@ rtc_source_set("rtc_base_tests_utils") { ":stringutils", "../test:field_trial", "../test:test_support", + "system:fallthrough", ] public_deps = [ "//testing/gtest", diff --git a/rtc_base/httpbase.cc b/rtc_base/httpbase.cc index d28d800c42..ca85b57567 100644 --- a/rtc_base/httpbase.cc +++ b/rtc_base/httpbase.cc @@ -21,6 +21,7 @@ #include "rtc_base/logging.h" #include "rtc_base/socket.h" #include "rtc_base/stringutils.h" +#include "rtc_base/system/fallthrough.h" #include "rtc_base/thread.h" namespace rtc { @@ -537,7 +538,7 @@ bool HttpBase::DoReceiveLoop(HttpError* error) { case SR_EOS: // Clean close, with no error. read_error = 0; - FALLTHROUGH(); // Fall through to HandleStreamClose. + RTC_FALLTHROUGH(); // Fall through to HandleStreamClose. case SR_ERROR: *error = HandleStreamClose(read_error); return true; diff --git a/rtc_base/system/BUILD.gn b/rtc_base/system/BUILD.gn new file mode 100644 index 0000000000..23d802acbc --- /dev/null +++ b/rtc_base/system/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2018 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. + +import("../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_source_set("fallthrough") { + sources = [ + "fallthrough.h", + ] +} diff --git a/rtc_base/system/fallthrough.h b/rtc_base/system/fallthrough.h new file mode 100644 index 0000000000..2bf0feac93 --- /dev/null +++ b/rtc_base/system/fallthrough.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 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. + */ + +#ifndef RTC_BASE_SYSTEM_FALLTHROUGH_H_ +#define RTC_BASE_SYSTEM_FALLTHROUGH_H_ + +// Macro to be used for switch-case fallthrough (required for enabling +// -Wimplicit-fallthrough warning on Clang). + +// This macro definition must not be included from public headers! Because +// clang's diagnostic checks if there's a macro expanding to +// [[clang::fallthrough]] defined, and if so it suggests the first macro +// expanding to it. So if this macro is included in a public header, clang may +// suggest it instead of the client's own macro, which can cause confusion. + +#ifdef __clang__ +#define RTC_FALLTHROUGH() [[clang::fallthrough]] +#else +#define RTC_FALLTHROUGH() \ + do { \ + } while (0) +#endif + +#endif // RTC_BASE_SYSTEM_FALLTHROUGH_H_ diff --git a/typedefs.h b/typedefs.h index 629cded1af..073b18024a 100644 --- a/typedefs.h +++ b/typedefs.h @@ -91,16 +91,6 @@ #endif #endif -// Macro to be used for switch-case fallthrough (required for enabling -// -Wimplicit-fallthrough warning on Clang). -#ifndef FALLTHROUGH -#if defined(__clang__) -#define FALLTHROUGH() [[clang::fallthrough]] -#else -#define FALLTHROUGH() do { } while (0) -#endif -#endif - #ifndef NO_RETURN // Annotate a function that will not return control flow to the caller. #if defined(_MSC_VER) diff --git a/video/BUILD.gn b/video/BUILD.gn index 79ade9e858..144987fec7 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -71,6 +71,7 @@ rtc_static_library("video") { "../modules/video_coding:video_codec_interface", "../rtc_base:checks", "../rtc_base/experiments:alr_experiment", + "../rtc_base/system:fallthrough", "../system_wrappers:field_trial_api", "../system_wrappers:metrics_api", diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc index 238eaf3474..7a06f1c479 100644 --- a/video/rtp_video_stream_receiver.cc +++ b/video/rtp_video_stream_receiver.cc @@ -34,6 +34,7 @@ #include "rtc_base/checks.h" #include "rtc_base/location.h" #include "rtc_base/logging.h" +#include "rtc_base/system/fallthrough.h" #include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/metrics.h" #include "system_wrappers/include/timestamp_extrapolator.h" @@ -253,7 +254,7 @@ int32_t RtpVideoStreamReceiver::OnReceivedPayloadData( switch (tracker_.CopyAndFixBitstream(&packet)) { case video_coding::H264SpsPpsTracker::kRequestKeyframe: keyframe_request_sender_->RequestKeyFrame(); - FALLTHROUGH(); + RTC_FALLTHROUGH(); case video_coding::H264SpsPpsTracker::kDrop: return 0; case video_coding::H264SpsPpsTracker::kInsert: diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 778f740a20..18f9d216a6 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -26,6 +26,7 @@ #include "rtc_base/checks.h" #include "rtc_base/location.h" #include "rtc_base/logging.h" +#include "rtc_base/system/fallthrough.h" #include "rtc_base/timeutils.h" #include "rtc_base/trace_event.h" #include "video/overuse_frame_detector.h" @@ -991,7 +992,7 @@ void VideoStreamEncoder::AdaptDown(AdaptReason reason) { break; } // Scale down resolution. - FALLTHROUGH(); + RTC_FALLTHROUGH(); } case VideoSendStream::DegradationPreference::kMaintainFramerate: { // Scale down resolution. @@ -1074,7 +1075,7 @@ void VideoStreamEncoder::AdaptUp(AdaptReason reason) { break; } // Scale up resolution. - FALLTHROUGH(); + RTC_FALLTHROUGH(); } case VideoSendStream::DegradationPreference::kMaintainFramerate: { // Scale up resolution.