Skip to content

Commit 7249f9c

Browse files
committed
[C++20] Fix a crash with spaceship and vector types
Vector types cannot be directly compared, you get an error when you try to do so. This patch causes the explicitly defaulted spaceship operator to be implicitly deleted. Fixes #137452
1 parent 764e0cc commit 7249f9c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ C++23 Feature Support
118118

119119
C++20 Feature Support
120120
^^^^^^^^^^^^^^^^^^^^^
121+
- Fixed a crash with a defaulted spaceship (``<=>``) operator when the class
122+
contains a member declaration of vector type. Vector types cannot yet be
123+
compared directly, so this causes the operator to be deleted. (#GH137452)
121124

122125
C++17 Feature Support
123126
^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8651,6 +8651,11 @@ class DefaultedComparisonAnalyzer
86518651
assert(Best->BuiltinParamTypes[2].isNull() &&
86528652
"invalid builtin comparison");
86538653

8654+
// FIXME: If the type we deduced is a vector type, we mark the
8655+
// comparison as deleted because we don't yet support this.
8656+
if (isa<VectorType>(T))
8657+
return Result::deleted();
8658+
86548659
if (NeedsDeducing) {
86558660
std::optional<ComparisonCategoryType> Cat =
86568661
getComparisonCategoryForBuiltinCmp(T);

clang/test/SemaCXX/cxx2a-three-way-comparison.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ namespace PR44325 {
5858
// implicit rewrite rules, not for explicit use by programs.
5959
bool c = cmp_cat() < 0; // expected-warning {{zero as null pointer constant}}
6060
}
61+
62+
namespace GH137452 {
63+
struct comparable_t {
64+
__attribute__((vector_size(32))) double numbers;
65+
auto operator<=>(const comparable_t& rhs) const = default; // expected-warning {{explicitly defaulted three-way comparison operator is implicitly deleted}} \
66+
expected-note {{replace 'default' with 'delete'}}
67+
};
68+
} // namespace GH137452

0 commit comments

Comments
 (0)