[clang] [Clang] Only omit deprecation warnings for implicit special members (PR #219177)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 28 05:17:53 PDT 2026


================
@@ -212,6 +212,10 @@ static bool ShouldDiagnoseAvailabilityInContext(
     } else if (K == AR_Deprecated) {
       if (C->isDeprecated())
         return true;
+      // Don't emit deprecated warnings when defining special member functions.
+      if (const auto *FD = dyn_cast<FunctionDecl>(C);
+          FD && FD->isDefaulted() && FD->isImplicit())
+        return true;
----------------
zyn0217 wrote:

I explored a bit:

`FD && FD->isDefaulted()` doesn't cause us to warn for implicit rewritten comparators, where the deprecated fields are involved when we synthesize the body.

If we added an availability check to DefaultedComparisonVisitor, that worked yet it resulted duplicated warnings. One when we synthesize the three-way comparator, the other when we synthesize the body of rewritten operators.

Both the two operators are Defaulted and we cannot distinguish them.

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


More information about the cfe-commits mailing list