diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9ab8031b9ea8c..33ee8a53b5f37 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -703,6 +703,7 @@ Bug Fixes in This Version the second clause of a C-style ``for`` loop. (#GH139818) - Fixed a bug with constexpr evaluation for structs containing unions in case of C++ modules. (#GH143168) - Fixed incorrect token location when emitting diagnostics for tokens expanded from macros. (#GH143216) +- Fixed an infinite recursion when checking constexpr destructors. (#GH141789) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 31e2834336742..6f62c53aaf04d 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -7159,7 +7159,10 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) { // "effectively constexpr" for better compatibility. // See https://github.com/llvm/llvm-project/issues/102293 for more info. if (isa(M)) { - auto Check = [](QualType T, auto &&Check) -> bool { + llvm::SmallDenseSet Visited; + auto Check = [&Visited](QualType T, auto &&Check) -> bool { + if (!Visited.insert(T->getCanonicalTypeUnqualified()).second) + return false; const CXXRecordDecl *RD = T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); if (!RD || !RD->isCompleteDefinition()) @@ -7168,16 +7171,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) { if (!RD->hasConstexprDestructor()) return false; - QualType CanUnqualT = T.getCanonicalType().getUnqualifiedType(); for (const CXXBaseSpecifier &B : RD->bases()) - if (B.getType().getCanonicalType().getUnqualifiedType() != - CanUnqualT && - !Check(B.getType(), Check)) + if (!Check(B.getType(), Check)) return false; for (const FieldDecl *FD : RD->fields()) - if (FD->getType().getCanonicalType().getUnqualifiedType() != - CanUnqualT && - !Check(FD->getType(), Check)) + if (!Check(FD->getType(), Check)) return false; return true; }; diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp index d4218cc13dcec..fe417e697841b 100644 --- a/clang/test/SemaCXX/gh102293.cpp +++ b/clang/test/SemaCXX/gh102293.cpp @@ -45,3 +45,20 @@ class quux : quux { // expected-error {{base class has incomplete type}} \ virtual int c(); }; } + +// Ensure we don't get infinite recursion from the check, however. See GH141789 +namespace GH141789 { +template +struct S { + Ty t; // expected-error {{field has incomplete type 'GH141789::X'}} +}; + +struct T { + ~T(); +}; + +struct X { // expected-note {{definition of 'GH141789::X' is not complete until the closing '}'}} + S next; // expected-note {{in instantiation of template class 'GH141789::S' requested here}} + T m; +}; +}