GN: Fix windows clang errors. Attempt 2.

BUG=webrtc:6255
NOTRY=True

Review-Url: https://codereview.webrtc.org/2281513002
Cr-Commit-Position: refs/heads/master@{#13942}
diff --git a/third_party/winsdk_samples/BUILD.gn b/third_party/winsdk_samples/BUILD.gn
index 82d1233..114f31f 100644
--- a/third_party/winsdk_samples/BUILD.gn
+++ b/third_party/winsdk_samples/BUILD.gn
@@ -13,6 +13,29 @@
     include_dirs = [ baseclasses_dir ]
   }
 
+  config("winsdk_samples_warnings_config") {
+    if (is_win && is_clang) {
+      cflags = [
+        # Disable warnings failing when compiling with Clang on Windows.
+        # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
+        "-Wno-comment",
+        "-Wno-delete-non-virtual-dtor",
+        "-Wno-ignored-attributes",
+        "-Wno-logical-op-parentheses",
+        "-Wno-non-pod-varargs",
+        "-Wno-microsoft-extra-qualification",
+        "-Wno-missing-braces",
+        "-Wno-overloaded-virtual",
+        "-Wno-parentheses",
+        "-Wno-reorder",
+        "-Wno-string-conversion",
+        "-Wno-tautological-constant-out-of-range-compare",
+        "-Wno-unused-private-field",
+        "-Wno-writable-strings",
+      ]
+    }
+  }
+
   static_library("winsdk_samples") {
     sources = [
       "$baseclasses_dir/amextra.cpp",
@@ -84,26 +107,9 @@
       "//build/config/compiler:chromium_code",
       "//build/config/win:nominmax",
     ]
-    configs += [ "//build/config/compiler:no_chromium_code" ]
-    if (is_win && is_clang) {
-      cflags += [
-        # Disable warnings failing when compiling with Clang on Windows.
-        # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
-        "-Wno-comment",
-        "-Wno-delete-non-virtual-dtor",
-        "-Wno-ignored-attributes",
-        "-Wno-logical-op-parentheses",
-        "-Wno-non-pod-varargs",
-        "-Wno-microsoft-extra-qualification",
-        "-Wno-missing-braces",
-        "-Wno-overloaded-virtual",
-        "-Wno-parentheses",
-        "-Wno-reorder",
-        "-Wno-string-conversion",
-        "-Wno-tautological-constant-out-of-range-compare",
-        "-Wno-unused-private-field",
-        "-Wno-writable-strings",
-      ]
-    }
+    configs += [
+      "//build/config/compiler:no_chromium_code",
+      ":winsdk_samples_warnings_config",
+    ]
   }
 }
diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn
index a1a4a86..2c26724 100644
--- a/webrtc/api/BUILD.gn
+++ b/webrtc/api/BUILD.gn
@@ -301,7 +301,12 @@
     # TODO(kjellander): Make the code compile without disabling these flags.
     # See https://bugs.webrtc.org/3307.
     if (is_clang && is_win) {
-      cflags = [ "-Wno-unused-function" ]
+      cflags = [
+        # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6267
+        # for -Wno-sign-compare
+        "-Wno-sign-compare",
+        "-Wno-unused-function",
+      ]
     }
 
     if (!is_win) {
diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn
index 49bd66a..a1748ca 100644
--- a/webrtc/base/BUILD.gn
+++ b/webrtc/base/BUILD.gn
@@ -236,6 +236,17 @@
   }
 }
 
+config("rtc_base_warnings_config") {
+  if (is_win && is_clang) {
+    cflags = [
+      # Disable warnings failing when compiling with Clang on Windows.
+      # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
+      "-Wno-sign-compare",
+      "-Wno-missing-braces",
+    ]
+  }
+}
+
 static_library("rtc_base") {
   cflags = []
   cflags_cc = []
@@ -260,7 +271,6 @@
   ]
 
   all_dependent_configs = [ ":rtc_base_all_dependent_config" ]
-
   defines = [ "LOGGING=1" ]
 
   sources = [
@@ -405,6 +415,14 @@
     "worker.h",
   ]
 
+  # TODO(henrike): issue 3307, make rtc_base build with the Chromium default
+  # compiler settings.
+  configs -= [ "//build/config/compiler:chromium_code" ]
+  configs += [ "//build/config/compiler:no_chromium_code" ]
+  if (!is_win) {
+    cflags += [ "-Wno-uninitialized" ]
+  }
+
   if (build_with_chromium) {
     if (is_win) {
       sources += [ "../../webrtc_overrides/webrtc/base/win32socketinit.cc" ]
@@ -417,6 +435,7 @@
 
     public_configs += [ ":rtc_base_chromium_config" ]
   } else {
+    configs += [ ":rtc_base_warnings_config" ]
     sources += [
       "bandwidthsmoother.cc",
       "bandwidthsmoother.h",
@@ -508,14 +527,6 @@
         "win32socketserver.h",
       ]
     }
-    if (is_win && is_clang) {
-      cflags += [
-        # Disable warnings failing when compiling with Clang on Windows.
-        # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
-        "-Wno-sign-compare",
-        "-Wno-missing-braces",
-      ]
-    }
 
     if (rtc_build_json) {
       deps += [ "//third_party/jsoncpp" ]
@@ -528,14 +539,6 @@
     }
   }  # !build_with_chromium
 
-  # TODO(henrike): issue 3307, make rtc_base build with the Chromium default
-  # compiler settings.
-  configs -= [ "//build/config/compiler:chromium_code" ]
-  configs += [ "//build/config/compiler:no_chromium_code" ]
-  if (!is_win) {
-    cflags += [ "-Wno-uninitialized" ]
-  }
-
   if (rtc_build_ssl) {
     deps += [ "//third_party/boringssl" ]
   } else {
@@ -665,6 +668,10 @@
     defines += [ "timezone=_timezone" ]
     sources -= [ "ifaddrs_converter.cc" ]
   }
+  if (is_clang) {
+    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+    configs -= [ "//build/config/clang:find_bad_constructs" ]
+  }
 }
 
 source_set("gtest_prod") {
@@ -678,6 +685,16 @@
     defines = [ "GTEST_RELATIVE_PATH" ]
   }
 
+  config("rtc_base_tests_utils_warnings_config") {
+    if (is_win && is_clang) {
+      cflags = [
+        # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6270
+        "-Wno-reorder",
+        "-Wno-sign-compare",
+      ]
+    }
+  }
+
   source_set("rtc_base_tests_utils") {
     testonly = true
     sources = [
@@ -696,7 +713,10 @@
       "timedelta.h",
       "unittest_main.cc",
     ]
-    configs += [ "..:common_config" ]
+    configs += [
+      "..:common_config",
+      ":rtc_base_tests_utils_warnings_config",
+    ]
     public_configs = [
       "..:common_inherited_config",
       ":rtc_base_tests_utils_exported_config",
@@ -709,6 +729,11 @@
     public_deps = [
       "//testing/gtest",
     ]
+
+    if (is_clang) {
+      # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+      configs -= [ "//build/config/clang:find_bad_constructs" ]
+    }
   }
 }
 
diff --git a/webrtc/examples/BUILD.gn b/webrtc/examples/BUILD.gn
index 8b1f187..c8078f4 100644
--- a/webrtc/examples/BUILD.gn
+++ b/webrtc/examples/BUILD.gn
@@ -391,6 +391,21 @@
     }
   }
 
+  config("peerconnection_client_warnings_config") {
+    if (is_win && is_clang) {
+      cflags = [
+        # Disable warnings failing when compiling with Clang on Windows.
+        # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
+        "-Wno-format",
+
+        # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6271
+        # for -Wno-reorder and -Wno-sign-compare
+        "-Wno-reorder",
+        "-Wno-sign-compare",
+      ]
+    }
+  }
+
   executable("peerconnection_client") {
     sources = [
       "peerconnection/client/conductor.cc",
@@ -415,14 +430,6 @@
       cflags = [ "/wd4245" ]
       configs += [ "//build/config/win:windowed" ]
     }
-    if (is_win && is_clang) {
-      cflags = [
-        # Disable warnings failing when compiling with Clang on Windows.
-        # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
-        "-Wno-reorder",
-        "-Wno-unused-function",
-      ]
-    }
     if (is_linux) {
       sources += [
         "peerconnection/client/linux/main.cc",
@@ -443,6 +450,7 @@
       "//webrtc/system_wrappers:field_trial_default",
       "//webrtc/system_wrappers:metrics_default",
     ]
+    configs += [ ":peerconnection_client_warnings_config" ]
     if (rtc_build_json) {
       deps += [ "//third_party/jsoncpp" ]
     }
diff --git a/webrtc/media/BUILD.gn b/webrtc/media/BUILD.gn
index 5f9a0af..c1eaea2 100644
--- a/webrtc/media/BUILD.gn
+++ b/webrtc/media/BUILD.gn
@@ -285,7 +285,12 @@
     # TODO(kjellander): Make the code compile without disabling these flags.
     # See https://bugs.webrtc.org/3307.
     if (is_clang && is_win) {
-      cflags = [ "-Wno-unused-function" ]
+      cflags = [
+        # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6266
+        # for -Wno-sign-compare
+        "-Wno-sign-compare",
+        "-Wno-unused-function",
+      ]
     }
     if (!is_win) {
       cflags = [ "-Wno-sign-compare" ]
diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn
index 0ea5035..8918347 100644
--- a/webrtc/modules/audio_coding/BUILD.gn
+++ b/webrtc/modules/audio_coding/BUILD.gn
@@ -1537,6 +1537,16 @@
     }
   }
 
+  config("isac_test_warnings_config") {
+    if (is_win && is_clang) {
+      cflags = [
+        # Disable warnings failing when compiling with Clang on Windows.
+        # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
+        "-Wno-format",
+      ]
+    }
+  }
+
   executable("isac_test") {
     testonly = true
 
@@ -1557,13 +1567,7 @@
       "//build/config/sanitizers:deps",
     ]
 
-    if (is_win && is_clang) {
-      cflags = [
-        # Disable warnings failing when compiling with Clang on Windows.
-        # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
-        "-Wno-format",
-      ]
-    }
+    configs += [ ":isac_test_warnings_config" ]
   }
 
   executable("g711_test") {
diff --git a/webrtc/modules/audio_device/BUILD.gn b/webrtc/modules/audio_device/BUILD.gn
index 8124210..a8867af 100644
--- a/webrtc/modules/audio_device/BUILD.gn
+++ b/webrtc/modules/audio_device/BUILD.gn
@@ -24,7 +24,37 @@
   }
 }
 
+config("audio_device_warnings_config") {
+  if (is_win && is_clang) {
+    cflags = [
+      # Disable warnings failing when compiling with Clang on Windows.
+      # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
+      "-Wno-bool-conversion",
+      "-Wno-delete-non-virtual-dtor",
+      "-Wno-logical-op-parentheses",
+      "-Wno-microsoft-extra-qualification",
+      "-Wno-microsoft-goto",
+      "-Wno-missing-braces",
+      "-Wno-parentheses-equality",
+      "-Wno-reorder",
+      "-Wno-shift-overflow",
+      "-Wno-tautological-compare",
+
+      # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6265
+      # for -Wno-thread-safety-analysis
+      "-Wno-thread-safety-analysis",
+      "-Wno-unused-private-field",
+    ]
+  }
+}
+
 source_set("audio_device") {
+  configs += [ "../..:common_config" ]
+  public_configs = [
+    "../..:common_inherited_config",
+    ":audio_device_config",
+  ]
+
   deps = [
     "../..:webrtc_common",
     "../../base:rtc_base",
@@ -193,23 +223,7 @@
           "msdmo.lib",
         ]
       }
-      if (is_win && is_clang) {
-        cflags += [
-          # Disable warnings failing when compiling with Clang on Windows.
-          # https://bugs.chromium.org/p/webrtc/issues/detail?id=5366
-          "-Wno-bool-conversion",
-          "-Wno-delete-non-virtual-dtor",
-          "-Wno-logical-op-parentheses",
-          "-Wno-microsoft-extra-qualification",
-          "-Wno-microsoft-goto",
-          "-Wno-missing-braces",
-          "-Wno-parentheses-equality",
-          "-Wno-reorder",
-          "-Wno-shift-overflow",
-          "-Wno-tautological-compare",
-          "-Wno-unused-private-field",
-        ]
-      }
+      configs += [ ":audio_device_warnings_config" ]
     }
   } else {
     defines = [ "WEBRTC_DUMMY_AUDIO_BUILD" ]
@@ -223,12 +237,6 @@
     ]
   }
 
-  configs += [ "../..:common_config" ]
-  public_configs = [
-    "../..:common_inherited_config",
-    ":audio_device_config",
-  ]
-
   if (is_clang) {
     # Suppress warnings from Chrome's Clang plugins.
     # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
diff --git a/webrtc/modules/video_capture/BUILD.gn b/webrtc/modules/video_capture/BUILD.gn
index 8edac89..0875ed8 100644
--- a/webrtc/modules/video_capture/BUILD.gn
+++ b/webrtc/modules/video_capture/BUILD.gn
@@ -76,7 +76,27 @@
     }
   }
 
+  config("video_capture_internal_impl_warnings_config") {
+    if (is_win && is_clang) {
+      cflags = [
+        "-Wno-comment",
+        "-Wno-ignored-attributes",
+
+        # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6269
+        # for -Wno-ignored-qualifiers
+        "-Wno-ignored-qualifiers",
+        "-Wno-microsoft-extra-qualification",
+        "-Wno-missing-braces",
+        "-Wno-overloaded-virtual",
+        "-Wno-reorder",
+        "-Wno-writable-strings",
+      ]
+    }
+  }
+
   source_set("video_capture_internal_impl") {
+    configs += [ ":video_capture_internal_impl_warnings_config" ]
+
     deps = [
       ":video_capture_module",
       "../../system_wrappers",
@@ -136,17 +156,6 @@
 
       deps += [ "//third_party/winsdk_samples" ]
     }
-    if (is_win && is_clang) {
-      cflags = [
-        "-Wno-comment",
-        "-Wno-ignored-attributes",
-        "-Wno-microsoft-extra-qualification",
-        "-Wno-missing-braces",
-        "-Wno-overloaded-virtual",
-        "-Wno-reorder",
-        "-Wno-writable-strings",
-      ]
-    }
     if (is_ios) {
       sources = [
         "ios/device_info_ios.h",
diff --git a/webrtc/stats/BUILD.gn b/webrtc/stats/BUILD.gn
index 3ef6188..50f4351 100644
--- a/webrtc/stats/BUILD.gn
+++ b/webrtc/stats/BUILD.gn
@@ -52,5 +52,11 @@
     if (is_android) {
       deps += [ "//testing/android/native_test:native_test_native_code" ]
     }
+
+    if (is_clang) {
+      # Suppress warnings from Chrome's Clang plugins.
+      # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
+      configs -= [ "//build/config/clang:find_bad_constructs" ]
+    }
   }
 }
diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn
index 6e1b0ae..826113d 100644
--- a/webrtc/system_wrappers/BUILD.gn
+++ b/webrtc/system_wrappers/BUILD.gn
@@ -133,6 +133,11 @@
     cflags = [ "/wd4334" ]  # Ignore warning on shift operator promotion.
   }
 
+  if (is_clang) {
+    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+    configs -= [ "//build/config/clang:find_bad_constructs" ]
+  }
+
   deps += [ "../base:rtc_base_approved" ]
 }
 
diff --git a/webrtc/test/BUILD.gn b/webrtc/test/BUILD.gn
index 2487976..9fd7d1a 100644
--- a/webrtc/test/BUILD.gn
+++ b/webrtc/test/BUILD.gn
@@ -33,13 +33,17 @@
     cflags = [ "/wd4302" ]  # cast truncation
 
     if (is_clang) {
-      # GN orders flags on a target before flags from configs. The default config
-      # adds -Wall, and this flag have to be after -Wall -- so they need to
-      # come from a config and cannot be on the target directly.
+      # GN orders flags on a target before flags from configs. The default
+      # config adds -Wall, and this flag have to be after -Wall -- so they need
+      # to come from a config and cannot be on the target directly.
       cflags += [
         "-Wno-parentheses-equality",
         "-Wno-reorder",
         "-Wno-tautological-constant-out-of-range-compare",
+
+        # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6268
+        # for -Wno-thread-safety-analysis
+        "-Wno-thread-safety-analysis",
         "-Wno-unused-private-field",
       ]
     }