Author: Younan Zhang Date: 2026-09-01T17:03:45+08:00 New Revision: dd1cb54f6a67e426b988b71653ed940b486dd805
URL: https://github.com/llvm/llvm-project/commit/dd1cb54f6a67e426b988b71653ed940b486dd805 DIFF: https://github.com/llvm/llvm-project/commit/dd1cb54f6a67e426b988b71653ed940b486dd805.diff LOG: [Clang] Only omit deprecation warnings for implicit special members (#219177) 31db0f0a7ae isn't very correct because synthesized deduction guides are also marked 'implicit', and it's supposed to apply to only non-user-defined special members. This patch corrects that behavior. Fixes #160543 Added: clang/test/SemaCXX/implicit-special-member-deprecated.cpp Modified: clang/docs/ReleaseNotes.md clang/lib/Sema/SemaAvailability.cpp Removed: clang/test/Sema/implicit-special-member-deprecated.cpp ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 82772714b5d46..0376f18c3d93f 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -566,6 +566,9 @@ features cannot lower the translation-unit ABI level; - Fixed an assertion during template argument deduction where a function parameter pack is referenced by other types in the function type. (#GH28877), (#GH213760) +- Fixed a regression where deprecation warnings were omitted for synthesized + deduction guide. (#GH160543) + - Fixed an assertion when a redeclaration of a function template or an out-of-line definition of a member of a class template added a default argument to a parameter that follows a parameter pack (e.g. diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp index 28a4b760dbd4d..636168d13d5b8 100644 --- a/clang/lib/Sema/SemaAvailability.cpp +++ b/clang/lib/Sema/SemaAvailability.cpp @@ -212,6 +212,9 @@ 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()) + return true; } else if (K == AR_Unavailable) { // It is perfectly fine to refer to an 'unavailable' Objective-C method // when it is referenced from within the @implementation itself. In this @@ -548,12 +551,6 @@ static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K, return; } case AR_Deprecated: - // Suppress -Wdeprecated-declarations in implicit - // functions. - if (const auto *FD = dyn_cast_or_null<FunctionDecl>(S.getCurFunctionDecl()); - FD && FD->isImplicit()) - return; - if (ObjCPropertyAccess) diag = diag::warn_property_method_deprecated; else if (S.currentEvaluationContext().IsCaseExpr) diff --git a/clang/test/Sema/implicit-special-member-deprecated.cpp b/clang/test/Sema/implicit-special-member-deprecated.cpp deleted file mode 100644 index 8e23404552f53..0000000000000 --- a/clang/test/Sema/implicit-special-member-deprecated.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// RUN: %clang_cc1 -std=c++20 -Wdeprecated-declarations -verify %s - -struct A { - [[deprecated("use something else")]] int x = 42; // expected-note {{marked deprecated here}} -}; - -A makeDefaultA() { return {}; } // ctor is implicit → no warn -A copyA(const A &a) { return a; } // copy-ctor implicit → no warn - -void assignA() { - A a, b; - a = b; // copy-assign implicit → no warn -} - -void useA() { - A a; - (void)a.x; // expected-warning {{is deprecated}} -} - -// Explicitly-defaulted ctor – now silent -struct B { - [[deprecated]] int y; - B() = default; // no warning under new policy -}; diff --git a/clang/test/SemaCXX/implicit-special-member-deprecated.cpp b/clang/test/SemaCXX/implicit-special-member-deprecated.cpp new file mode 100644 index 0000000000000..60d235ce625ac --- /dev/null +++ b/clang/test/SemaCXX/implicit-special-member-deprecated.cpp @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -std=c++20 -Wdeprecated-declarations -I%S/Inputs -verify %s + +#include "std-compare.h" + +namespace GH147293 { +struct A { + [[deprecated("use something else")]] int x = 42; // expected-note {{marked deprecated here}} +}; + +A makeDefaultA() { return {}; } // ctor is implicit -> no warn +A copyA(const A &a) { return a; } // copy-ctor implicit -> no warn + +void assignA() { + A a, b; + a = b; // copy-assign implicit -> no warn +} + +void useA() { + A a; + (void)a.x; // expected-warning {{is deprecated}} +} + +// Explicitly-defaulted ctor – now silent +struct B { + [[deprecated]] int y; + B() = default; // no warning under new policy +}; + +} + +namespace GH147293_regression { + +struct A { + [[deprecated("use something else")]] int x = 42; + auto operator<=>(const A&) const = default; +}; + +struct B : A { + bool operator==(const B&) const = default; +}; + +void foo() { + A x, y; + (void)(x == y); + (void)(x < y); + + B bx, by; + (void)(bx != by); +} + +} + +namespace GH160543 { + +template<class F> +struct [[deprecated]] X { X(F);}; // expected-warning {{is deprecated}} expected-note {{deprecated here}} + +void f() { + X x{0}; // expected-note {{while substituting}} +} + +} + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
