Author: Oleksandr T. Date: 2024-07-29T18:39:30+02:00 New Revision: ee57ce57d8094026e2795182758bc57027a72293
URL: https://github.com/llvm/llvm-project/commit/ee57ce57d8094026e2795182758bc57027a72293 DIFF: https://github.com/llvm/llvm-project/commit/ee57ce57d8094026e2795182758bc57027a72293.diff LOG: [Clang] prevent checking destructor reference with an invalid initializer (#97860) Fixes #97230 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaInit.cpp clang/test/SemaCXX/destructor.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e93582b50cfb2..92f0a44c5ad72 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -163,6 +163,7 @@ Bug Fixes to C++ Support - Fixed a crash when an expression with a dependent ``__typeof__`` type is used as the operand of a unary operator. (#GH97646) - Fixed a failed assertion when checking invalid delete operator declaration. (#GH96191) +- Fix a crash when checking destructor reference with an invalid initializer. (#GH97230) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index dc2ba039afe7f..90fd6df782f09 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1986,6 +1986,9 @@ static bool checkDestructorReference(QualType ElementType, SourceLocation Loc, return false; CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD); + if (!Destructor) + return false; + SemaRef.CheckDestructorAccess(Loc, Destructor, SemaRef.PDiag(diag::err_access_dtor_temp) << ElementType); diff --git a/clang/test/SemaCXX/destructor.cpp b/clang/test/SemaCXX/destructor.cpp index 028bc7cc19698..dfcd1b033af5a 100644 --- a/clang/test/SemaCXX/destructor.cpp +++ b/clang/test/SemaCXX/destructor.cpp @@ -577,4 +577,13 @@ static_assert(!__is_trivially_constructible(Foo, const Foo &), ""); static_assert(!__is_trivially_constructible(Foo, Foo &&), ""); } // namespace GH89544 +namespace GH97230 { +struct X { + ~X() = defaul; // expected-error {{initializer on function does not look like a pure-specifier}} \ + // expected-error {{use of undeclared identifier 'defaul'}} +}; +struct Y : X {} y1{ }; // expected-error {{call to implicitly-deleted default constructor of 'struct Y'}} \ + // expected-note {{default constructor of 'Y' is implicitly deleted because base class 'X' has no destructor}} +} + #endif // BE_THE_HEADER _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits