Move FALLTHROUGH macro to a separate header, and give it an RTC_ prefix

Bug: chromium:805946
Change-Id: Ibb5dce9af27d0e48c9aee6b0a860b6f62b3c76a0
Reviewed-on: https://webrtc-review.googlesource.com/46145
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21889}
diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn
index 4ed6377..c9c5ff1 100644
--- a/modules/audio_coding/BUILD.gn
+++ b/modules/audio_coding/BUILD.gn
@@ -1080,6 +1080,7 @@
     "../../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 85e3690..b107626 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 @@
           static_cast<uint32_t>(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 fd0f937..3efab79 100644
--- a/modules/audio_device/BUILD.gn
+++ b/modules/audio_device/BUILD.gn
@@ -82,6 +82,7 @@
       "../../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 c350969..48bd7e1 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 @@
       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 1c95043..ddd77d1 100644
--- a/modules/remote_bitrate_estimator/BUILD.gn
+++ b/modules/remote_bitrate_estimator/BUILD.gn
@@ -142,6 +142,7 @@
       "../../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 cf72f29..656cb5b 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 @@
     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 7180d50..24f3b75 100644
--- a/modules/rtp_rtcp/BUILD.gn
+++ b/modules/rtp_rtcp/BUILD.gn
@@ -212,6 +212,7 @@
     "../../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 57a7955..226cc36 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 @@
       }
       case H264::NaluType::kIdr:
         parsed_payload->frame_type = kVideoFrameKey;
-        FALLTHROUGH();
+        RTC_FALLTHROUGH();
       case H264::NaluType::kSlice: {
         rtc::Optional<uint32_t> 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 b337d71..16717b4 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -122,6 +122,7 @@
     "../../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 aefe6ae..079780c 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 @@
           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 512d6f2..79f11cd 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 @@
         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 f0e2fd7..4d5b9d6 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -879,6 +879,7 @@
     ":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 d28d800..ca85b57 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 @@
       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 0000000..23d802a
--- /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 0000000..2bf0fea
--- /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 629cded..073b180 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 79ade9e..144987f 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -71,6 +71,7 @@
     "../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 238eaf3..7a06f1c 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 @@
     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 778f740..18f9d21 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 @@
         break;
       }
       // Scale down resolution.
-      FALLTHROUGH();
+      RTC_FALLTHROUGH();
     }
     case VideoSendStream::DegradationPreference::kMaintainFramerate: {
       // Scale down resolution.
@@ -1074,7 +1075,7 @@
         break;
       }
       // Scale up resolution.
-      FALLTHROUGH();
+      RTC_FALLTHROUGH();
     }
     case VideoSendStream::DegradationPreference::kMaintainFramerate: {
       // Scale up resolution.