[llvm-branch-commits] [clang] release/23.x: Revert "Reland "[Clang] Enable -Wunused-template under -Wall" (#208001)" (#218638) (PR #218678)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 25 06:09:47 PDT 2026


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/218678

Backport 8710728e04184f0a695a3898effd40df5a2b8aef

Requested by: @cor3ntin

>From c08860d2359e112297e9c4635c19eca487d82146 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Tue, 25 Aug 2026 14:21:49 +0200
Subject: [PATCH] Revert "Reland "[Clang] Enable -Wunused-template under -Wall"
 (#208001)" (#218638)

This reverts commit 1529d35adbd6f13aa234a5f4cfd9ac0e28bdd338.

There are two issues:
- The change appear fairly disruptive so close to release (see comments
on #208001)
 - there are false positives (see #218429)

(cherry picked from commit 8710728e04184f0a695a3898effd40df5a2b8aef)
---
 clang/docs/ReleaseNotes.md                      | 5 -----
 clang/include/clang/Basic/DiagnosticGroups.td   | 2 +-
 clang/test/Misc/warning-wall.c                  | 2 --
 clang/test/SemaCXX/warn-func-not-needed.cpp     | 2 +-
 clang/test/SemaCXX/warn-variable-not-needed.cpp | 2 +-
 5 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 17cf79d648a70..75096c92fa245 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -605,11 +605,6 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
   allowing it to be disabled independently with `-Wno-unused-but-set-global`.
   (#GH148361)
 
-- `-Wunused-template` is now part of `-Wunused` (which is enabled by `-Wall`).
-  It diagnoses unused function and variable templates with internal linkage,
-  which in a header is a latent ODR hazard. It can be disabled with
-  `-Wno-unused-template`. (#GH202945)
-
 - Added `-Wlifetime-safety` to enable lifetime safety analysis,
   a CFG-based intra-procedural analysis that detects use-after-free and related
   temporal safety bugs. See the
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index b7072634cccf3..b3c3b25aa4b2e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1370,7 +1370,7 @@ def Conversion
 def Unused : DiagGroup<"unused",
                        [UnusedArgument, UnusedFunction, UnusedLabel,
                         // UnusedParameter, (matches GCC's behavior)
-                        UnusedTemplate,
+                        // UnusedTemplate, (clean-up libc++ before enabling)
                         // UnusedMemberFunction, (clean-up llvm before enabling)
                         UnusedPrivateField, UnusedLambdaCapture,
                         UnusedLocalTypedef, UnusedValue, UnusedVariable,
diff --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index ade9cbaace77e..6d6c4e562400f 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -73,8 +73,6 @@ CHECK-NEXT:      -Wunused-argument
 CHECK-NEXT:      -Wunused-function
 CHECK-NEXT:        -Wunneeded-internal-declaration
 CHECK-NEXT:      -Wunused-label
-CHECK-NEXT:      -Wunused-template
-CHECK-NEXT:        -Wunneeded-internal-declaration
 CHECK-NEXT:      -Wunused-private-field
 CHECK-NEXT:      -Wunused-lambda-capture
 CHECK-NEXT:      -Wunused-local-typedef
diff --git a/clang/test/SemaCXX/warn-func-not-needed.cpp b/clang/test/SemaCXX/warn-func-not-needed.cpp
index 74438543c43b7..cb3cae4cd6c76 100644
--- a/clang/test/SemaCXX/warn-func-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-func-not-needed.cpp
@@ -10,7 +10,7 @@ void foo() {
 }
 
 namespace test1_template {
-template <typename T> static void f() {} // expected-warning {{unused function template}}
+template <typename T> static void f() {}
 template <> void f<int>() {} // expected-warning {{function 'f<int>' is not needed and will not be emitted}}
 template <typename T>
 void foo() {
diff --git a/clang/test/SemaCXX/warn-variable-not-needed.cpp b/clang/test/SemaCXX/warn-variable-not-needed.cpp
index d234e9140e3fd..272c8998d15c0 100644
--- a/clang/test/SemaCXX/warn-variable-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-variable-not-needed.cpp
@@ -4,7 +4,7 @@ namespace test1 {
   static int abc = 42; // expected-warning {{variable 'abc' is not needed and will not be emitted}}
 
   namespace {
-  template <typename T> int abc_template = 0; // expected-warning {{unused variable template}}
+  template <typename T> int abc_template = 0;
   template <> int abc_template<int> = 0; // expected-warning {{variable 'abc_template<int>' is not needed and will not be emitted}}
   }                                      // namespace
   template <typename T>



More information about the llvm-branch-commits mailing list