[clang] 4de66e8 - [clang] __is_trivially_equality_comparable should return false for arrays
Nikolas Klauser via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 26 09:37:03 PDT 2023
Author: Nikolas Klauser
Date: 2023-06-26T09:36:58-07:00
New Revision: 4de66e8c44348fb1e85268b10a7f862381e695c7
URL: https://github.com/llvm/llvm-project/commit/4de66e8c44348fb1e85268b10a7f862381e695c7
DIFF: https://github.com/llvm/llvm-project/commit/4de66e8c44348fb1e85268b10a7f862381e695c7.diff
LOG: [clang] __is_trivially_equality_comparable should return false for arrays
When comparing two arrays, their pointers are compared instead of their elements, which means that they are not trivially equality comparable
Fixes #63371
Reviewed By: cor3ntin
Spies: cor3ntin, cfe-commits
Differential Revision: https://reviews.llvm.org/D153737
Added:
Modified:
clang/lib/AST/Type.cpp
clang/test/SemaCXX/type-traits.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index f16c024c044b7..646eba90973f5 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2684,7 +2684,7 @@ bool QualType::isTriviallyEqualityComparableType(
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()) {
diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index d5388d4eb89be..9bb093e985cfc 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3110,7 +3110,7 @@ static_assert(!__is_trivially_equality_comparable(ForwardDeclared), ""); // expe
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 @@ struct TriviallyEqualityComparable {
};
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();
More information about the cfe-commits
mailing list