pkasting updated this revision to Diff 519188. pkasting added a comment. Update test per review comments.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D149713/new/ https://reviews.llvm.org/D149713 Files: clang/lib/Sema/SemaDeclCXX.cpp clang/test/SemaCXX/warn-exit-time-destructors.cpp clang/test/SemaCXX/warn-global-constructors.cpp Index: clang/test/SemaCXX/warn-global-constructors.cpp =================================================================== --- clang/test/SemaCXX/warn-global-constructors.cpp +++ clang/test/SemaCXX/warn-global-constructors.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wglobal-constructors %s -verify +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wglobal-constructors %s -verify=expected,cxx11 +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wglobal-constructors %s -verify=expected int opaque_int(); @@ -145,3 +146,22 @@ const HasUnnamedBitfield nonConstexprConst{1}; // expected-warning {{global constructor}} HasUnnamedBitfield nonConstexprMutable{1}; // expected-warning {{global constructor}} } + +namespace test7 { +#if __cplusplus >= 202002L +#define CPP20_CONSTEXPR constexpr +#else +#define CPP20_CONSTEXPR +#endif + struct S { + CPP20_CONSTEXPR ~S() {} + }; + S s; // cxx11-warning {{global destructor}} + + struct T { + CPP20_CONSTEXPR ~T() { if (b) {} } + bool b; + }; + T t; // expected-warning {{global destructor}} +#undef CPP20_CONSTEXPR +} Index: clang/test/SemaCXX/warn-exit-time-destructors.cpp =================================================================== --- clang/test/SemaCXX/warn-exit-time-destructors.cpp +++ clang/test/SemaCXX/warn-exit-time-destructors.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wexit-time-destructors %s -verify +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wexit-time-destructors %s -verify=expected,cxx11 +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wexit-time-destructors %s -verify=expected namespace test1 { struct A { ~A(); }; @@ -48,3 +49,22 @@ struct A { ~A(); }; [[clang::no_destroy]] A a; // no warning } + +namespace test5 { +#if __cplusplus >= 202002L +#define CPP20_CONSTEXPR constexpr +#else +#define CPP20_CONSTEXPR +#endif + struct S { + CPP20_CONSTEXPR ~S() {} + }; + S s; // cxx11-warning {{exit-time destructor}} + + struct T { + CPP20_CONSTEXPR ~T() { if (b) {} } + bool b; + }; + T t; // expected-warning {{exit-time destructor}} +#undef CPP20_CONSTEXPR +} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -15718,7 +15718,8 @@ } } - if (!VD->hasGlobalStorage()) return; + if (!VD->hasGlobalStorage() || !VD->needsDestruction(Context)) + return; // Emit warning for non-trivial dtor in global scope (a real global, // class-static, function-static).
Index: clang/test/SemaCXX/warn-global-constructors.cpp =================================================================== --- clang/test/SemaCXX/warn-global-constructors.cpp +++ clang/test/SemaCXX/warn-global-constructors.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wglobal-constructors %s -verify +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wglobal-constructors %s -verify=expected,cxx11 +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wglobal-constructors %s -verify=expected int opaque_int(); @@ -145,3 +146,22 @@ const HasUnnamedBitfield nonConstexprConst{1}; // expected-warning {{global constructor}} HasUnnamedBitfield nonConstexprMutable{1}; // expected-warning {{global constructor}} } + +namespace test7 { +#if __cplusplus >= 202002L +#define CPP20_CONSTEXPR constexpr +#else +#define CPP20_CONSTEXPR +#endif + struct S { + CPP20_CONSTEXPR ~S() {} + }; + S s; // cxx11-warning {{global destructor}} + + struct T { + CPP20_CONSTEXPR ~T() { if (b) {} } + bool b; + }; + T t; // expected-warning {{global destructor}} +#undef CPP20_CONSTEXPR +} Index: clang/test/SemaCXX/warn-exit-time-destructors.cpp =================================================================== --- clang/test/SemaCXX/warn-exit-time-destructors.cpp +++ clang/test/SemaCXX/warn-exit-time-destructors.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wexit-time-destructors %s -verify +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wexit-time-destructors %s -verify=expected,cxx11 +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wexit-time-destructors %s -verify=expected namespace test1 { struct A { ~A(); }; @@ -48,3 +49,22 @@ struct A { ~A(); }; [[clang::no_destroy]] A a; // no warning } + +namespace test5 { +#if __cplusplus >= 202002L +#define CPP20_CONSTEXPR constexpr +#else +#define CPP20_CONSTEXPR +#endif + struct S { + CPP20_CONSTEXPR ~S() {} + }; + S s; // cxx11-warning {{exit-time destructor}} + + struct T { + CPP20_CONSTEXPR ~T() { if (b) {} } + bool b; + }; + T t; // expected-warning {{exit-time destructor}} +#undef CPP20_CONSTEXPR +} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -15718,7 +15718,8 @@ } } - if (!VD->hasGlobalStorage()) return; + if (!VD->hasGlobalStorage() || !VD->needsDestruction(Context)) + return; // Emit warning for non-trivial dtor in global scope (a real global, // class-static, function-static).
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits