Skip to content

Commit 06bf100

Browse files
authored
[C++20] Fix a crash with spaceship and vector types (#139767)
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 bbc5221 commit 06bf100

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

clang/docs/ReleaseNotes.rst

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

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

124127
C++17 Feature Support
125128
^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10185,6 +10185,9 @@ def note_defaulted_comparison_no_viable_function_synthesized : Note<
1018510185
def note_defaulted_comparison_not_rewritten_callee : Note<
1018610186
"defaulted %0 is implicitly deleted because this non-rewritten comparison "
1018710187
"function would be the best match for the comparison">;
10188+
def note_defaulted_comparison_vector_types : Note<
10189+
"defaulted %0 is implicitly deleted because defaulted comparison of vector "
10190+
"types is not supported">;
1018810191
def note_defaulted_comparison_not_rewritten_conversion : Note<
1018910192
"defaulted %0 is implicitly deleted because a builtin comparison function "
1019010193
"using this conversion would be the best match for the comparison">;

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8651,6 +8651,18 @@ 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+
if (Diagnose == ExplainDeleted) {
8658+
S.Diag(FD->getLocation(),
8659+
diag::note_defaulted_comparison_vector_types)
8660+
<< FD;
8661+
S.Diag(Subobj.Decl->getLocation(), diag::note_declared_at);
8662+
}
8663+
return Result::deleted();
8664+
}
8665+
86548666
if (NeedsDeducing) {
86558667
std::optional<ComparisonCategoryType> Cat =
86568668
getComparisonCategoryForBuiltinCmp(T);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,12 @@ 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; // expected-note {{declared here}}
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+
expected-note {{defaulted 'operator<=>' is implicitly deleted because defaulted comparison of vector types is not supported}}
68+
};
69+
} // namespace GH137452

0 commit comments

Comments
 (0)