[clang] e98776a - [clang] Add __is_trivially_equality_comparable
Nikolas Klauser via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 17 06:36:27 PDT 2023
Author: Nikolas Klauser
Date: 2023-04-17T15:36:21+02:00
New Revision: e98776a180a74c08dcc07cebf26c11deac6e975a
URL: https://github.com/llvm/llvm-project/commit/e98776a180a74c08dcc07cebf26c11deac6e975a
DIFF: https://github.com/llvm/llvm-project/commit/e98776a180a74c08dcc07cebf26c11deac6e975a.diff
LOG: [clang] Add __is_trivially_equality_comparable
This patch adds a new trait to allow standard libraries to forward `std::equal` calls to `memcmp` in more cases.
Reviewed By: aaron.ballman
Spies: Mordante, shafik, xbolva00, libcxx-commits, cfe-commits, ldionne
Differential Revision: https://reviews.llvm.org/D147175
Added:
Modified:
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/TokenKinds.def
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp
Removed:
################################################################################
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index cda08066c6ab2..ddd366b637e59 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1507,6 +1507,9 @@ The following type trait primitives are supported by Clang. Those traits marked
functionally equivalent to copying the underlying bytes and then dropping the
source object on the floor. This is true of trivial types and types which
were made trivially relocatable via the ``clang::trivial_abi`` attribute.
+* ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two
+ objects of the provided type is known to be equivalent to comparing their
+ value representations.
* ``__is_unbounded_array`` (C++, GNU, Microsoft, Embarcadero)
* ``__is_union`` (C++, GNU, Microsoft, Embarcadero)
* ``__is_unsigned`` (C++, Embarcadero):
@@ -4928,7 +4931,7 @@ Note, all of debugging pragmas are subject to change.
`dump`
------
Accepts either a single identifier or an expression. When a single identifier is passed,
-the lookup results for the identifier are printed to `stderr`. When an expression is passed,
+the lookup results for the identifier are printed to `stderr`. When an expression is passed,
the AST for the expression is printed to `stderr`. The expression is an unevaluated operand,
so things like overload resolution and template instantiations are performed,
but the expression has no runtime effects.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4fb1160713def..9c8a0e1faa326 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -150,6 +150,9 @@ Non-comprehensive list of changes in this release
- Clang now supports expressions in ``#pragma clang __debug dump``.
- Clang now supports declaration of multi-dimensional arrays with
``__declspec(property)``.
+- A new builtin type trait ``__is_trivially_equaltiy_comparable`` has been added,
+ which checks whether comparing two instances of a type is equivalent to
+ ``memcmp(&lhs, &rhs, sizeof(T)) == 0``.
New Compiler Flags
------------------
@@ -287,7 +290,7 @@ Bug Fixes in This Version
- Fix crash when handling nested immediate invocations in initializers of global
variables.
(`#58207 <https://github.com/llvm/llvm-project/issues/58207>`_)
-- Fix crash when generating code coverage information for `PseudoObjectExpr` in
+- Fix crash when generating code coverage information for `PseudoObjectExpr` in
Clang AST.
(`#45481 <https://github.com/llvm/llvm-project/issues/45481>`_)
- Fix the assertion hit when a template consteval function appears in a nested
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 26626192e338f..54b41d248a341 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2492,7 +2492,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// Return true if the specified type has unique object representations
/// according to (C++17 [meta.unary.prop]p9)
- bool hasUniqueObjectRepresentations(QualType Ty) const;
+ bool
+ hasUniqueObjectRepresentations(QualType Ty,
+ bool CheckIfTriviallyCopyable = true) const;
//===--------------------------------------------------------------------===//
// Type Operators
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 9ecc29bd38fd1..af0e724311017 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -899,6 +899,9 @@ class QualType {
/// Return true if this is a trivially relocatable type.
bool isTriviallyRelocatableType(const ASTContext &Context) const;
+ /// Return true if this is a trivially equality comparable type.
+ bool isTriviallyEqualityComparableType(const ASTContext &Context) const;
+
/// Returns true if it is a class and it might be dynamic.
bool mayBeDynamicClass() const;
diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
index 28862c81e9ee1..f17a6028a137a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -519,6 +519,7 @@ TYPE_TRAIT_1(__has_unique_object_representations,
// Clang-only C++ Type Traits
TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
+TYPE_TRAIT_1(__is_trivially_equality_comparable, IsTriviallyEqualityComparable, KEYCXX)
TYPE_TRAIT_1(__is_bounded_array, IsBoundedArray, KEYCXX)
TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 87c908ae5f561..ab54dd80e5ef2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2668,12 +2668,14 @@ void ASTContext::CollectInheritedProtocols(const Decl *CDecl,
}
static bool unionHasUniqueObjectRepresentations(const ASTContext &Context,
- const RecordDecl *RD) {
+ const RecordDecl *RD,
+ bool CheckIfTriviallyCopyable) {
assert(RD->isUnion() && "Must be union type");
CharUnits UnionSize = Context.getTypeSizeInChars(RD->getTypeForDecl());
for (const auto *Field : RD->fields()) {
- if (!Context.hasUniqueObjectRepresentations(Field->getType()))
+ if (!Context.hasUniqueObjectRepresentations(Field->getType(),
+ CheckIfTriviallyCopyable))
return false;
CharUnits FieldSize = Context.getTypeSizeInChars(Field->getType());
if (FieldSize != UnionSize)
@@ -2696,21 +2698,25 @@ static int64_t getSubobjectOffset(const CXXRecordDecl *RD,
static std::optional<int64_t>
structHasUniqueObjectRepresentations(const ASTContext &Context,
- const RecordDecl *RD);
+ const RecordDecl *RD,
+ bool CheckIfTriviallyCopyable);
static std::optional<int64_t>
-getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) {
+getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context,
+ bool CheckIfTriviallyCopyable) {
if (Field->getType()->isRecordType()) {
const RecordDecl *RD = Field->getType()->getAsRecordDecl();
if (!RD->isUnion())
- return structHasUniqueObjectRepresentations(Context, RD);
+ return structHasUniqueObjectRepresentations(Context, RD,
+ CheckIfTriviallyCopyable);
}
// A _BitInt type may not be unique if it has padding bits
// but if it is a bitfield the padding bits are not used.
bool IsBitIntType = Field->getType()->isBitIntType();
if (!Field->getType()->isReferenceType() && !IsBitIntType &&
- !Context.hasUniqueObjectRepresentations(Field->getType()))
+ !Context.hasUniqueObjectRepresentations(Field->getType(),
+ CheckIfTriviallyCopyable))
return std::nullopt;
int64_t FieldSizeInBits =
@@ -2730,25 +2736,28 @@ getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) {
return std::nullopt;
}
FieldSizeInBits = BitfieldSize;
- } else if (IsBitIntType &&
- !Context.hasUniqueObjectRepresentations(Field->getType())) {
+ } else if (IsBitIntType && !Context.hasUniqueObjectRepresentations(
+ Field->getType(), CheckIfTriviallyCopyable)) {
return std::nullopt;
}
return FieldSizeInBits;
}
static std::optional<int64_t>
-getSubobjectSizeInBits(const CXXRecordDecl *RD, const ASTContext &Context) {
- return structHasUniqueObjectRepresentations(Context, RD);
+getSubobjectSizeInBits(const CXXRecordDecl *RD, const ASTContext &Context,
+ bool CheckIfTriviallyCopyable) {
+ return structHasUniqueObjectRepresentations(Context, RD,
+ CheckIfTriviallyCopyable);
}
template <typename RangeT>
static std::optional<int64_t> structSubobjectsHaveUniqueObjectRepresentations(
const RangeT &Subobjects, int64_t CurOffsetInBits,
- const ASTContext &Context, const clang::ASTRecordLayout &Layout) {
+ const ASTContext &Context, const clang::ASTRecordLayout &Layout,
+ bool CheckIfTriviallyCopyable) {
for (const auto *Subobject : Subobjects) {
std::optional<int64_t> SizeInBits =
- getSubobjectSizeInBits(Subobject, Context);
+ getSubobjectSizeInBits(Subobject, Context, CheckIfTriviallyCopyable);
if (!SizeInBits)
return std::nullopt;
if (*SizeInBits != 0) {
@@ -2763,7 +2772,8 @@ static std::optional<int64_t> structSubobjectsHaveUniqueObjectRepresentations(
static std::optional<int64_t>
structHasUniqueObjectRepresentations(const ASTContext &Context,
- const RecordDecl *RD) {
+ const RecordDecl *RD,
+ bool CheckIfTriviallyCopyable) {
assert(!RD->isUnion() && "Must be struct/class type");
const auto &Layout = Context.getASTRecordLayout(RD);
@@ -2784,8 +2794,8 @@ structHasUniqueObjectRepresentations(const ASTContext &Context,
});
std::optional<int64_t> OffsetAfterBases =
- structSubobjectsHaveUniqueObjectRepresentations(Bases, CurOffsetInBits,
- Context, Layout);
+ structSubobjectsHaveUniqueObjectRepresentations(
+ Bases, CurOffsetInBits, Context, Layout, CheckIfTriviallyCopyable);
if (!OffsetAfterBases)
return std::nullopt;
CurOffsetInBits = *OffsetAfterBases;
@@ -2793,7 +2803,8 @@ structHasUniqueObjectRepresentations(const ASTContext &Context,
std::optional<int64_t> OffsetAfterFields =
structSubobjectsHaveUniqueObjectRepresentations(
- RD->fields(), CurOffsetInBits, Context, Layout);
+ RD->fields(), CurOffsetInBits, Context, Layout,
+ CheckIfTriviallyCopyable);
if (!OffsetAfterFields)
return std::nullopt;
CurOffsetInBits = *OffsetAfterFields;
@@ -2801,7 +2812,8 @@ structHasUniqueObjectRepresentations(const ASTContext &Context,
return CurOffsetInBits;
}
-bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const {
+bool ASTContext::hasUniqueObjectRepresentations(
+ QualType Ty, bool CheckIfTriviallyCopyable) const {
// C++17 [meta.unary.prop]:
// The predicate condition for a template specialization
// has_unique_object_representations<T> shall be
@@ -2823,10 +2835,11 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const {
// Arrays are unique only if their element type is unique.
if (Ty->isArrayType())
- return hasUniqueObjectRepresentations(getBaseElementType(Ty));
+ return hasUniqueObjectRepresentations(getBaseElementType(Ty),
+ CheckIfTriviallyCopyable);
// (9.1) - T is trivially copyable...
- if (!Ty.isTriviallyCopyableType(*this))
+ if (CheckIfTriviallyCopyable && !Ty.isTriviallyCopyableType(*this))
return false;
// All integrals and enums are unique.
@@ -2854,10 +2867,11 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const {
return false;
if (Record->isUnion())
- return unionHasUniqueObjectRepresentations(*this, Record);
+ return unionHasUniqueObjectRepresentations(*this, Record,
+ CheckIfTriviallyCopyable);
- std::optional<int64_t> StructSize =
- structHasUniqueObjectRepresentations(*this, Record);
+ std::optional<int64_t> StructSize = structHasUniqueObjectRepresentations(
+ *this, Record, CheckIfTriviallyCopyable);
return StructSize && *StructSize == static_cast<int64_t>(getTypeSize(Ty));
}
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 276b5aa59f759..e1686a7c69d52 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2594,6 +2594,50 @@ bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {
}
}
+static bool
+HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
+ if (Decl->isUnion())
+ return false;
+
+ if (llvm::none_of(Decl->methods(), [](const CXXMethodDecl *MemberFunction) {
+ return MemberFunction->isOverloadedOperator() &&
+ MemberFunction->getOverloadedOperator() ==
+ OverloadedOperatorKind::OO_EqualEqual &&
+ MemberFunction->isDefaulted();
+ }))
+ return false;
+
+ return llvm::all_of(Decl->bases(),
+ [](const CXXBaseSpecifier &BS) {
+ if (const auto *RD = BS.getType()->getAsCXXRecordDecl())
+ HasNonDeletedDefaultedEqualityComparison(RD);
+ return true;
+ }) &&
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+ auto Type = FD->getType();
+ if (Type->isReferenceType() || Type->isEnumeralType())
+ return false;
+ if (const auto *RD = Type->getAsCXXRecordDecl())
+ return HasNonDeletedDefaultedEqualityComparison(RD);
+ return true;
+ });
+}
+
+bool QualType::isTriviallyEqualityComparableType(
+ const ASTContext &Context) const {
+ QualType CanonicalType = getCanonicalType();
+ if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType() ||
+ CanonicalType->isEnumeralType())
+ return false;
+
+ if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
+ if (!HasNonDeletedDefaultedEqualityComparison(RD))
+ return false;
+ }
+
+ return Context.hasUniqueObjectRepresentations(CanonicalType);
+}
+
bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const {
return !Context.getLangOpts().ObjCAutoRefCount &&
Context.getLangOpts().ObjCWeak &&
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 0617d29aed712..69595c455b47a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4870,8 +4870,10 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
case UTT_IsStandardLayout:
case UTT_IsPOD:
case UTT_IsLiteral:
- // By analogy, is_trivially_relocatable imposes the same constraints.
+ // By analogy, is_trivially_relocatable and is_trivially_equality_comparable
+ // impose the same constraints.
case UTT_IsTriviallyRelocatable:
+ case UTT_IsTriviallyEqualityComparable:
case UTT_CanPassInRegs:
// Per the GCC type traits documentation, T shall be a complete type, cv void,
// or an array of unknown bound. But GCC actually imposes the same constraints
@@ -5366,6 +5368,8 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
return RD->canPassInRegisters();
Self.Diag(KeyLoc, diag::err_builtin_pass_in_regs_non_class) << T;
return false;
+ case UTT_IsTriviallyEqualityComparable:
+ return T.isTriviallyEqualityComparableType(C);
}
}
diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index cc0a83706475d..f9003b704099f 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++1z -fblocks -Wno-deprecated-builtins %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++17 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++20 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s
#define T(b) (b) ? 1 : -1
#define F(b) (b) ? -1 : 1
@@ -570,7 +571,11 @@ void is_aggregate()
static_assert(__is_aggregate(DerivesAr), "");
static_assert(__is_aggregate(DerivesArNB), "");
static_assert(!__is_aggregate(HasCons), "");
+#if __cplusplus >= 202002L
+ static_assert(!__is_aggregate(HasDefaultCons), "");
+#else
static_assert(__is_aggregate(HasDefaultCons), "");
+#endif
static_assert(!__is_aggregate(HasExplicitDefaultCons), "");
static_assert(!__is_aggregate(HasInheritedCons), "");
static_assert(__is_aggregate(HasNoInheritedCons) == TrueAfterCpp14, "");
@@ -3098,6 +3103,168 @@ static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor[]), "");
} // namespace is_trivially_relocatable
+namespace is_trivially_equality_comparable {
+struct ForwardDeclared; // expected-note {{forward declaration of 'is_trivially_equality_comparable::ForwardDeclared'}}
+static_assert(!__is_trivially_equality_comparable(ForwardDeclared), ""); // expected-error {{incomplete type 'ForwardDeclared' used in type trait expression}}
+
+static_assert(!__is_trivially_equality_comparable(void), "");
+static_assert(__is_trivially_equality_comparable(int), "");
+static_assert(!__is_trivially_equality_comparable(int[]), "");
+static_assert(__is_trivially_equality_comparable(int[3]), "");
+static_assert(!__is_trivially_equality_comparable(float), "");
+static_assert(!__is_trivially_equality_comparable(double), "");
+static_assert(!__is_trivially_equality_comparable(long double), "");
+
+struct TriviallyEqualityComparableNoDefaultedComparator {
+ int i;
+ int j;
+};
+static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator), "");
+
+#if __cplusplus >= 202002L
+
+struct TriviallyEqualityComparable {
+ int i;
+ int j;
+
+ void func();
+ bool operator==(int) const { return false; }
+
+ bool operator==(const TriviallyEqualityComparable&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), "");
+
+struct NotTriviallyEqualityComparableHasPadding {
+ short i;
+ int j;
+
+ bool operator==(const NotTriviallyEqualityComparableHasPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasPadding), "");
+
+struct NotTriviallyEqualityComparableHasFloat {
+ float i;
+ int j;
+
+ bool operator==(const NotTriviallyEqualityComparableHasFloat&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasFloat), "");
+
+struct NotTriviallyEqualityComparableHasTailPadding {
+ int i;
+ char j;
+
+ bool operator==(const NotTriviallyEqualityComparableHasTailPadding&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasTailPadding), "");
+
+struct NotTriviallyEqualityComparableBase : NotTriviallyEqualityComparableHasTailPadding {
+ char j;
+
+ bool operator==(const NotTriviallyEqualityComparableBase&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBase), "");
+
+class TriviallyEqualityComparablePaddedOutBase {
+ int i;
+ char c;
+
+public:
+ bool operator==(const TriviallyEqualityComparablePaddedOutBase&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOutBase), "");
+
+struct TriviallyEqualityComparablePaddedOut : TriviallyEqualityComparablePaddedOutBase {
+ char j[3];
+
+ bool operator==(const TriviallyEqualityComparablePaddedOut&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOut), "");
+
+struct TriviallyEqualityComparable1 {
+ char i;
+
+ bool operator==(const TriviallyEqualityComparable1&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable1));
+
+struct TriviallyEqualityComparable2 {
+ int i;
+
+ bool operator==(const TriviallyEqualityComparable2&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable2));
+
+struct NotTriviallyEqualityComparableTriviallyEqualityComparableBases
+ : TriviallyEqualityComparable1, TriviallyEqualityComparable2 {
+ bool operator==(const NotTriviallyEqualityComparableTriviallyEqualityComparableBases&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableTriviallyEqualityComparableBases));
+
+struct NotTriviallyEqualityComparableBitfield {
+ int i : 1;
+
+ bool operator==(const NotTriviallyEqualityComparableBitfield&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield));
+
+// TODO: This is trivially equality comparable
+struct NotTriviallyEqualityComparableBitfieldFilled {
+ char i : __CHAR_BIT__;
+
+ bool operator==(const NotTriviallyEqualityComparableBitfieldFilled&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield));
+
+union U {
+ int i;
+
+ bool operator==(const U&) const = default;
+};
+
+struct NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion {
+ U u;
+
+ bool operator==(const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion));
+
+struct NotTriviallyEqualityComparableExplicitlyDeleted {
+ int i;
+
+ bool operator==(const NotTriviallyEqualityComparableExplicitlyDeleted&) const = delete;
+};
+
+struct NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct {
+ NotTriviallyEqualityComparableExplicitlyDeleted u;
+
+ bool operator==(const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct));
+
+struct NotTriviallyEqualityComparableHasReferenceMember {
+ int& i;
+
+ bool operator==(const NotTriviallyEqualityComparableHasReferenceMember&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasReferenceMember));
+
+enum E {
+ a,
+ b
+};
+bool operator==(E, E) { return false; }
+static_assert(!__is_trivially_equality_comparable(E));
+
+struct NotTriviallyEqualityComparableHasEnum {
+ E e;
+ bool operator==(const NotTriviallyEqualityComparableHasEnum&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasEnum));
+
+#endif // __cplusplus >= 202002L
+};
+
namespace can_pass_in_regs {
struct A { };
More information about the cfe-commits
mailing list