[clang] [clang] Treat templates referenced in unevaluated operands as used for -Wunused-template (PR #234168)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 23 01:46:55 PDT 2026


================
@@ -908,10 +908,17 @@ static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
 
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     // If this is a function template and none of its specializations is used,
-    // we should warn.
+    // we should warn. A specialization that was implicitly instantiated only
+    // because it was named in an unevaluated operand (decltype, sizeof,
+    // noexcept, a requires-expression) is referenced but never odr-used and
+    // never gets a body; the template still determined the meaning of that
+    // expression, so treat it as a use.
----------------
zyn0217 wrote:

The instantiation of declaration does track the specialization list, can you explain why you think there is a connection with the definition instantiation?

https://github.com/llvm/llvm-project/pull/234168


More information about the cfe-commits mailing list