https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/113575
>From 67a48d3861b44bd5c37fc9740ee2c54ddd1a8d1b Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Thu, 24 Oct 2024 17:21:39 +0300 Subject: [PATCH 1/2] [Clang] enhance handling of [[deprecated]] attribute diagnostics for local variables --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaAvailability.cpp | 6 ++++++ clang/test/SemaCXX/deprecated.cpp | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 28bb83a1c9d60f..89c97d4b6631f2 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -424,6 +424,8 @@ Improvements to Clang's diagnostics name was a reserved name, which we improperly allowed to suppress the diagnostic. +- Clang now diagnoses [[deprecated]] attribute usage on local variables (#GH90073). + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp index 798cabaa31a476..d62b3eb1a480e7 100644 --- a/clang/lib/Sema/SemaAvailability.cpp +++ b/clang/lib/Sema/SemaAvailability.cpp @@ -182,6 +182,12 @@ static bool ShouldDiagnoseAvailabilityInContext( return false; } + if (K == AR_Deprecated) { + if (const auto *VD = dyn_cast<VarDecl>(OffendingDecl)) + if (VD->isLocalVarDecl() && VD->isDeprecated()) + return true; + } + // Checks if we should emit the availability diagnostic in the context of C. auto CheckContext = [&](const Decl *C) { if (K == AR_NotYetIntroduced) { diff --git a/clang/test/SemaCXX/deprecated.cpp b/clang/test/SemaCXX/deprecated.cpp index a93331023f7e21..02fdf0bec5c088 100644 --- a/clang/test/SemaCXX/deprecated.cpp +++ b/clang/test/SemaCXX/deprecated.cpp @@ -260,5 +260,19 @@ namespace ArrayComp { bool b7 = arr1 == +f(); } +namespace GH90073 { +[[deprecated]] int f() { // expected-note {{'f' has been explicitly marked deprecated here}} + [[deprecated]] int a; // expected-note {{'a' has been explicitly marked deprecated here}} \ + // expected-note {{'a' has been explicitly marked deprecated here}} + a = 0; // expected-warning {{'a' is deprecated}} + return a; // expected-warning {{'a' is deprecated}} +} + +int main() { + f(); // expected-warning {{'f' is deprecated}} + return 0; +} +} + # 1 "/usr/include/system-header.h" 1 3 void system_header_function(void) throw(); >From 9ae5428ad5f69b8d6b7a0923f2daf3e059b212c9 Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Fri, 25 Oct 2024 10:10:15 +0300 Subject: [PATCH 2/2] handle deprecated parameter declarations --- clang/docs/ReleaseNotes.rst | 2 +- clang/lib/Sema/SemaAvailability.cpp | 2 +- clang/test/SemaCXX/deprecated.cpp | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 89c97d4b6631f2..c100dacef53cd9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -424,7 +424,7 @@ Improvements to Clang's diagnostics name was a reserved name, which we improperly allowed to suppress the diagnostic. -- Clang now diagnoses [[deprecated]] attribute usage on local variables (#GH90073). +- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073). Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp index d62b3eb1a480e7..076d3489fa9438 100644 --- a/clang/lib/Sema/SemaAvailability.cpp +++ b/clang/lib/Sema/SemaAvailability.cpp @@ -184,7 +184,7 @@ static bool ShouldDiagnoseAvailabilityInContext( if (K == AR_Deprecated) { if (const auto *VD = dyn_cast<VarDecl>(OffendingDecl)) - if (VD->isLocalVarDecl() && VD->isDeprecated()) + if (VD->isLocalVarDeclOrParm() && VD->isDeprecated()) return true; } diff --git a/clang/test/SemaCXX/deprecated.cpp b/clang/test/SemaCXX/deprecated.cpp index 02fdf0bec5c088..667f4d7d3edb03 100644 --- a/clang/test/SemaCXX/deprecated.cpp +++ b/clang/test/SemaCXX/deprecated.cpp @@ -261,15 +261,21 @@ namespace ArrayComp { } namespace GH90073 { -[[deprecated]] int f() { // expected-note {{'f' has been explicitly marked deprecated here}} +[[deprecated]] int f1() { // expected-note {{'f1' has been explicitly marked deprecated here}} [[deprecated]] int a; // expected-note {{'a' has been explicitly marked deprecated here}} \ // expected-note {{'a' has been explicitly marked deprecated here}} a = 0; // expected-warning {{'a' is deprecated}} return a; // expected-warning {{'a' is deprecated}} } +[[deprecated]] void f2([[deprecated]] int x) { // expected-note {{'f2' has been explicitly marked deprecated here}} \ + // expected-note {{'x' has been explicitly marked deprecated here}} + x = 4; // expected-warning {{'x' is deprecated}} +} + int main() { - f(); // expected-warning {{'f' is deprecated}} + f1(); // expected-warning {{'f1' is deprecated}} + f2(1); // expected-warning {{'f2' is deprecated}} return 0; } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits