[clang] c6b4433 - [clang] Fix __is_trivially_equality_comparable for classes which contain arrays of non-trivially equality comparable types

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 10 11:09:47 PDT 2023


Author: Nikolas Klauser
Date: 2023-07-10T11:09:38-07:00
New Revision: c6b4433a0f20c5ebbd72cee8fd0dcfdb429e619c

URL: https://github.com/llvm/llvm-project/commit/c6b4433a0f20c5ebbd72cee8fd0dcfdb429e619c
DIFF: https://github.com/llvm/llvm-project/commit/c6b4433a0f20c5ebbd72cee8fd0dcfdb429e619c.diff

LOG: [clang] Fix __is_trivially_equality_comparable for classes which contain arrays of non-trivially equality comparable types

Fixes #63656

Reviewed By: cor3ntin

Spies: tbaeder, cfe-commits

Differential Revision: https://reviews.llvm.org/D154778

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 7ffed145c5fe55..a1b17577fba717 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2672,6 +2672,9 @@ HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
                       }) &&
          llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
            auto Type = FD->getType();
+           if (Type->isArrayType())
+             Type = Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
+
            if (Type->isReferenceType() || Type->isEnumeralType())
              return false;
            if (const auto *RD = Type->getAsCXXRecordDecl())

diff  --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index ba52ca748fed73..0fb364eaf36266 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3141,6 +3141,13 @@ struct TriviallyEqualityComparableContainsArray {
 };
 static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsArray));
 
+struct TriviallyEqualityComparableContainsMultiDimensionArray {
+  int a[4][4];
+
+  bool operator==(const TriviallyEqualityComparableContainsMultiDimensionArray&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();
@@ -3292,6 +3299,20 @@ struct NotTriviallyEqualityComparableHasEnum {
 };
 static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasEnum));
 
+struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs {
+  E e[1];
+
+  bool operator==(const NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs));
+
+struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2 {
+  E e[1][1];
+
+  bool operator==(const NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2));
+
 namespace hidden_friend {
 
 struct TriviallyEqualityComparable {


        


More information about the cfe-commits mailing list