https://github.com/ycdtosa created https://github.com/llvm/llvm-project/pull/86486
user wants the warning silenced by the attribute so no warning should be issued. >From 016152bc21c2625db77d3e31a7123bcf08114133 Mon Sep 17 00:00:00 2001 From: ycdtosa <ycdt...@gmail.com> Date: Mon, 25 Mar 2024 10:28:02 +0000 Subject: [PATCH] add test for [[clang::always-destroy]] attribute user wants the warning silenced by the attribute so no warning should be issued --- clang/lib/Sema/SemaDeclCXX.cpp | 3 ++- clang/test/SemaCXX/warn-exit-time-destructors.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index ee732679417e37..7070ea00cff275 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -16202,7 +16202,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) { // Emit warning for non-trivial dtor in global scope (a real global, // class-static, function-static). - Diag(VD->getLocation(), diag::warn_exit_time_destructor); + if (!VD->hasAttr<AlwaysDestroyAttr>()) + Diag(VD->getLocation(), diag::warn_exit_time_destructor); // TODO: this should be re-enabled for static locals by !CXAAtExit if (!VD->isStaticLocal()) diff --git a/clang/test/SemaCXX/warn-exit-time-destructors.cpp b/clang/test/SemaCXX/warn-exit-time-destructors.cpp index 2f14243cb48c47..8bd798c036333e 100644 --- a/clang/test/SemaCXX/warn-exit-time-destructors.cpp +++ b/clang/test/SemaCXX/warn-exit-time-destructors.cpp @@ -51,6 +51,11 @@ struct A { ~A(); }; } namespace test5 { +struct A { ~A(); }; +[[clang::always_destroy]] A a; // no warning +} + +namespace test6 { #if __cplusplus >= 202002L #define CPP20_CONSTEXPR constexpr #else @@ -68,3 +73,4 @@ namespace test5 { T t; // expected-warning {{exit-time destructor}} #undef CPP20_CONSTEXPR } + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits