Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
14 changes: 6 additions & 8 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CXXDestructorDecl>(M)) {
auto Check = [](QualType T, auto &&Check) -> bool {
llvm::SmallDenseSet<QualType> 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())
Expand All @@ -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;
};
Expand Down
17 changes: 17 additions & 0 deletions clang/test/SemaCXX/gh102293.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Ty>
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<X> next; // expected-note {{in instantiation of template class 'GH141789::S<GH141789::X>' requested here}}
T m;
};
}
Loading