pw_build: Restrict -Wno-unused-template to Clang

The -Wno-unused-template warning option is Clang-specific. On GCC
compilers (such as arm-zephyr-eabi-gcc), passing this flag produces
spurious diagnostics when compilation fails or generates warnings:
"note: unrecognized command-line option '-Wno-unused-template' may have
been intended to silence earlier diagnostics".

Restrict -Wno-unused-template to Clang across CMake, GN, and Bazel
strict warning configurations, matching the pattern used for the
deprecated-attributes warning exemption.

Change-Id: Ifcd3993b2f6ad9348fc081e2e0cf170b234d44e5
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/480645
diff --git a/pw_build/BUILD.gn b/pw_build/BUILD.gn
index d54ac0d..926055d 100644
--- a/pw_build/BUILD.gn
+++ b/pw_build/BUILD.gn
@@ -194,15 +194,15 @@
     "-Werror",
     "-Wno-error=cpp",  # preprocessor #warning statement
     "-Wno-error=deprecated-declarations",  # [[deprecated]] attribute
-
-    # TODO: b/535724234 - Unblock LLVM toolchain roll. New detection of unused
-    # templates produces warnings in both Pigweed an downstream code. While
-    # the Pigweed fixes are easy, the downstream fixes will take a while.
-    "-Wno-unused-template",
   ]
   if (is_clang) {
     # TODO: b/540919302 - Unblock LLVM toolchain roll.
     cflags += [ "-Wno-error=deprecated-attributes" ]
+
+    # TODO: b/535724234 - Unblock LLVM toolchain roll. New detection of unused
+    # templates produces warnings in both Pigweed an downstream code. While
+    # the Pigweed fixes are easy, the downstream fixes will take a while.
+    cflags += [ "-Wno-unused-template" ]
   }
   cflags_cc = [ "-Wnon-virtual-dtor" ]
 }
diff --git a/pw_build/CMakeLists.txt b/pw_build/CMakeLists.txt
index fc89f83..6aebdf8 100644
--- a/pw_build/CMakeLists.txt
+++ b/pw_build/CMakeLists.txt
@@ -100,7 +100,8 @@
     # TODO: b/535724234 - Unblock LLVM toolchain roll. New detection of unused
     # templates produces warnings in both Pigweed an downstream code. While
     # the Pigweed fixes are easy, the downstream fixes will take a while.
-    "-Wno-unused-template"
+    $<$<C_COMPILER_ID:Clang>:-Wno-unused-template>
+    $<$<CXX_COMPILER_ID:Clang>:-Wno-unused-template>
 
     $<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>
 )
diff --git a/pw_toolchain/cc/args/BUILD.bazel b/pw_toolchain/cc/args/BUILD.bazel
index 0e3c929..6628ce2 100644
--- a/pw_toolchain/cc/args/BUILD.bazel
+++ b/pw_toolchain/cc/args/BUILD.bazel
@@ -104,12 +104,6 @@
         "-Werror",
         "-Wno-error=cpp",  # preprocessor #warning statement
         "-Wno-error=deprecated-declarations",  # [[deprecated]] attribute
-
-        # TODO: b/535724234 - Unblock LLVM toolchain roll. New detection of
-        # unused templates produces warnings in both Pigweed an downstream
-        # code. While the Pigweed fixes are easy, the downstream fixes will
-        # take a while.
-        "-Wno-unused-template",
     ],
 )
 
@@ -123,6 +117,12 @@
     args = [
         # TODO: b/540919302 - Unblock LLVM toolchain roll.
         "-Wno-error=deprecated-attributes",
+
+        # TODO: b/535724234 - Unblock LLVM toolchain roll. New detection of
+        # unused templates produces warnings in both Pigweed an downstream
+        # code. While the Pigweed fixes are easy, the downstream fixes will
+        # take a while.
+        "-Wno-unused-template",
     ],
     requires_any_of = [
         ":compiler_is_clang",