Skip to content

Commit c9fd92d

Browse files
committed
[clang] Improve diagnostics on implicitly deleted defaulted comparisons
This patch just makes the error message clearer by reinforcing the cause was a lack of viable **three-way** comparison function for the **complete object**. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D97990
1 parent bbd0dc3 commit c9fd92d

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8979,8 +8979,8 @@ def note_defaulted_comparison_calls_deleted : Note<
89798979
"defaulted %0 is implicitly deleted because it would invoke a deleted "
89808980
"comparison function%select{| for member %2| for base class %2}1">;
89818981
def note_defaulted_comparison_no_viable_function : Note<
8982-
"defaulted %0 is implicitly deleted because there is no viable comparison "
8983-
"function%select{| for member %2| for base class %2}1">;
8982+
"defaulted %0 is implicitly deleted because there is no viable three-way "
8983+
"comparison function for%select{| member| base class}1 %2">;
89848984
def note_defaulted_comparison_no_viable_function_synthesized : Note<
89858985
"three-way comparison cannot be synthesized because there is no viable "
89868986
"function for %select{'=='|'<'}0 comparison">;

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7632,7 +7632,7 @@ class DefaultedComparisonAnalyzer
76327632

76337633
private:
76347634
Subobject getCompleteObject() {
7635-
return Subobject{Subobject::CompleteObject, nullptr, FD->getLocation()};
7635+
return Subobject{Subobject::CompleteObject, RD, FD->getLocation()};
76367636
}
76377637

76387638
Subobject getBase(CXXBaseSpecifier *Base) {

clang/test/CXX/class/class.compare/class.compare.default/p1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace P1946 {
127127
friend bool operator==(A &, A &); // expected-note {{would lose const qualifier}}
128128
};
129129
struct B {
130-
A a; // expected-note {{no viable comparison}}
130+
A a; // expected-note {{no viable three-way comparison}}
131131
friend bool operator==(B, B) = default; // ok
132132
friend bool operator==(const B&, const B&) = default; // expected-warning {{deleted}}
133133
};

clang/test/CXX/class/class.compare/class.compare.default/p2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct A3 {
4444

4545
bool operator==(const A3 &) const = default; // expected-warning {{implicitly deleted}}
4646
bool operator<(const A3 &) const = default; // expected-warning {{implicitly deleted}}
47-
// expected-note@-1 {{because there is no viable comparison function}}
47+
// expected-note@-1 {{because there is no viable three-way comparison function for 'A3'}}
4848
};
4949

5050
struct B1 {

clang/test/CXX/class/class.compare/class.compare.default/p4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace DeleteAfterFirstDecl {
9999
struct Q {
100100
struct X {
101101
friend std::strong_ordering operator<=>(const X&, const X&);
102-
} x; // expected-note {{no viable comparison}}
102+
} x; // expected-note {{no viable three-way comparison}}
103103
// expected-error@+1 {{defaulting the corresponding implicit 'operator==' for this defaulted 'operator<=>' would delete it after its first declaration}}
104104
friend std::strong_ordering operator<=>(const Q&, const Q&) = default;
105105
};

clang/test/CXX/class/class.compare/class.eq/p2.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ struct G { bool operator==(G) const = delete; }; // expected-note {{deleted here
1818
struct H1 {
1919
bool operator==(const H1 &) const = default;
2020
bool operator<(const H1 &) const = default; // expected-warning {{implicitly deleted}}
21-
// expected-note@-1 {{because there is no viable comparison function}}
21+
// expected-note@-1 {{because there is no viable three-way comparison function for 'H1'}}
2222
void (*x)();
2323
};
2424
struct H2 {
2525
bool operator==(const H2 &) const = default;
2626
bool operator<(const H2 &) const = default; // expected-warning {{implicitly deleted}}
27-
// expected-note@-1 {{because there is no viable comparison function}}
27+
// expected-note@-1 {{because there is no viable three-way comparison function for 'H2'}}
2828
void (H2::*x)();
2929
};
3030
struct H3 {
3131
bool operator==(const H3 &) const = default;
3232
bool operator<(const H3 &) const = default; // expected-warning {{implicitly deleted}}
33-
// expected-note@-1 {{because there is no viable comparison function}}
33+
// expected-note@-1 {{because there is no viable three-way comparison function for 'H3'}}
3434
int H3::*x;
3535
};
3636

3737
template<typename T> struct X {
3838
X();
3939
bool operator==(const X&) const = default; // #x expected-note 4{{deleted here}}
40-
T t; // expected-note 3{{because there is no viable comparison function for member 't'}}
40+
T t; // expected-note 3{{because there is no viable three-way comparison function for member 't'}}
4141
// expected-note@-1 {{because it would invoke a deleted comparison function for member 't'}}
4242
};
4343

clang/test/CXX/class/class.compare/class.spaceship/p1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ namespace Deletedness {
7878
};
7979

8080
// expected-note@#base {{deleted comparison function for base class 'C'}}
81-
// expected-note@#base {{no viable comparison function for base class 'D1'}}
81+
// expected-note@#base {{no viable three-way comparison function for base class 'D1'}}
8282
// expected-note@#base {{three-way comparison cannot be synthesized because there is no viable function for '<' comparison}}
83-
// expected-note@#base {{no viable comparison function for base class 'D2'}}
83+
// expected-note@#base {{no viable three-way comparison function for base class 'D2'}}
8484
// expected-note@#base {{three-way comparison cannot be synthesized because there is no viable function for '==' comparison}}
8585
// expected-note@#base {{deleted comparison function for base class 'E'}}
8686
// expected-note@#base {{implied comparison for base class 'F' is ambiguous}}
@@ -110,9 +110,9 @@ namespace Deletedness {
110110
}
111111

112112
// expected-note@#arr {{deleted comparison function for member 'arr'}}
113-
// expected-note@#arr {{no viable comparison function for member 'arr'}}
113+
// expected-note@#arr {{no viable three-way comparison function for member 'arr'}}
114114
// expected-note@#arr {{three-way comparison cannot be synthesized because there is no viable function for '<' comparison}}
115-
// expected-note@#arr {{no viable comparison function for member 'arr'}}
115+
// expected-note@#arr {{no viable three-way comparison function for member 'arr'}}
116116
// expected-note@#arr {{three-way comparison cannot be synthesized because there is no viable function for '==' comparison}}
117117
// expected-note@#arr {{deleted comparison function for member 'arr'}}
118118
// expected-note@#arr {{implied comparison for member 'arr' is ambiguous}}

clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace DeducedVsSynthesized {
5252
bool operator<(const A&) const;
5353
};
5454
struct B {
55-
A a; // expected-note {{no viable comparison function for member 'a'}}
55+
A a; // expected-note {{no viable three-way comparison function for member 'a'}}
5656
auto operator<=>(const B&) const = default; // expected-warning {{implicitly deleted}}
5757
};
5858
}
@@ -159,16 +159,16 @@ namespace BadDeducedType {
159159
namespace PR48856 {
160160
struct A {
161161
auto operator<=>(const A &) const = default; // expected-warning {{implicitly deleted}}
162-
void (*x)(); // expected-note {{because there is no viable comparison function for member 'x'}}
162+
void (*x)(); // expected-note {{because there is no viable three-way comparison function for member 'x'}}
163163
};
164164

165165
struct B {
166166
auto operator<=>(const B &) const = default; // expected-warning {{implicitly deleted}}
167-
void (B::*x)(); // expected-note {{because there is no viable comparison function for member 'x'}}
167+
void (B::*x)(); // expected-note {{because there is no viable three-way comparison function for member 'x'}}
168168
};
169169

170170
struct C {
171171
auto operator<=>(const C &) const = default; // expected-warning {{implicitly deleted}}
172-
int C::*x; // expected-note {{because there is no viable comparison function for member 'x'}}
172+
int C::*x; // expected-note {{because there is no viable three-way comparison function for member 'x'}}
173173
};
174174
}

0 commit comments

Comments
 (0)