[PATCH] D153737: [clang] __is_trivially_equality_comparable should return false for arrays
Nikolas Klauser via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 25 20:20:15 PDT 2023
philnik created this revision.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
When comparing two arrays, their pointers are compared instead of their elements, which menas that they are not trivially equality comparable
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153737
Files:
clang/lib/AST/Type.cpp
clang/test/SemaCXX/type-traits.cpp
Index: clang/test/SemaCXX/type-traits.cpp
===================================================================
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3110,7 +3110,7 @@
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(int[3]), "");
static_assert(!__is_trivially_equality_comparable(float), "");
static_assert(!__is_trivially_equality_comparable(double), "");
static_assert(!__is_trivially_equality_comparable(long double), "");
@@ -3134,6 +3134,13 @@
};
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), "");
+struct TriviallyEqualityComparableContainsArray {
+ int a[4];
+
+ bool operator==(const TriviallyEqualityComparableContainsArray&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsArray));
+
struct TriviallyEqualityComparableNonTriviallyCopyable {
TriviallyEqualityComparableNonTriviallyCopyable(const TriviallyEqualityComparableNonTriviallyCopyable&);
~TriviallyEqualityComparableNonTriviallyCopyable();
Index: clang/lib/AST/Type.cpp
===================================================================
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2684,7 +2684,7 @@
const ASTContext &Context) const {
QualType CanonicalType = getCanonicalType();
if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType() ||
- CanonicalType->isEnumeralType())
+ CanonicalType->isEnumeralType() || CanonicalType->isArrayType())
return false;
if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153737.534412.patch
Type: text/x-patch
Size: 1850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230626/80f65a03/attachment.bin>
More information about the cfe-commits
mailing list