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 @@ -432,6 +432,7 @@ Bug Fixes to C++ Support
- Fix an assertion failure when taking the address on a non-type template parameter argument of
object type. (#GH151531)
- Suppress ``-Wdouble-promotion`` when explicitly asked for with C++ list initialization (#GH33409).
- Fix the result of `__builtin_is_implicit_lifetime` for types with a user-provided constructor. (#GH160610)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
17 changes: 10 additions & 7 deletions clang/lib/Sema/SemaTypeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,13 +1163,16 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
// - it has at least one trivial eligible constructor and a trivial,
// non-deleted destructor.
const CXXDestructorDecl *Dtor = RD->getDestructor();
if (UnqualT->isAggregateType())
if (Dtor && !Dtor->isUserProvided())
return true;
if (RD->hasTrivialDestructor() && (!Dtor || !Dtor->isDeleted()))
if (RD->hasTrivialDefaultConstructor() ||
RD->hasTrivialCopyConstructor() || RD->hasTrivialMoveConstructor())
return true;
if (UnqualT->isAggregateType() && (!Dtor || !Dtor->isUserProvided()))
return true;
if (RD->hasTrivialDestructor() && (!Dtor || !Dtor->isDeleted())) {
for (CXXConstructorDecl *Ctr : RD->ctors()) {
if (Ctr->isIneligibleOrNotSelected() || Ctr->isDeleted())
continue;
if (Ctr->isTrivial())
return true;
}
}
return false;
}
case UTT_IsIntangibleType:
Expand Down
43 changes: 43 additions & 0 deletions clang/test/SemaCXX/type-traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,49 @@ void is_implicit_lifetime(int n) {
static_assert(__builtin_is_implicit_lifetime(int * __restrict));
}

namespace GH160610 {
class NonAggregate {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a few more combinations here, like combinations of defaulted and deleted.

public:
NonAggregate() = default;

NonAggregate(const NonAggregate&) = delete;
NonAggregate& operator=(const NonAggregate&) = delete;
private:
int num;
};

class DataMemberInitializer {
public:
DataMemberInitializer() = default;

DataMemberInitializer(const DataMemberInitializer&) = delete;
DataMemberInitializer& operator=(const DataMemberInitializer&) = delete;
private:
int num = 0;
};

class UserProvidedConstructor {
public:
UserProvidedConstructor() {}

UserProvidedConstructor(const UserProvidedConstructor&) = delete;
UserProvidedConstructor& operator=(const UserProvidedConstructor&) = delete;
};

static_assert(__builtin_is_implicit_lifetime(NonAggregate));
static_assert(!__builtin_is_implicit_lifetime(DataMemberInitializer));
static_assert(!__builtin_is_implicit_lifetime(UserProvidedConstructor));

#if __cplusplus >= 202002L
template <typename T>
class Tpl {
Tpl() requires false = default ;
};
static_assert(!__builtin_is_implicit_lifetime(Tpl<int>));

#endif
}

void is_signed()
{
//static_assert(__is_signed(char));
Expand Down