Skip to content

Commit 6b67b56

Browse files
Jeff Palmfacebook-github-bot
Jeff Palm
authored andcommitted
util/ribbon_test.cc: avoid ambiguous reversed operator error in c++20 (facebook#11371)
Summary: util/ribbon_test.cc: avoid ambiguous reversed operator error in c++20 (and enable checking for the error) Code would produce errors like this, when compiled with -Wambiguous-reversed-operator under c++20. ``` util/ribbon_test.cc:695:20: error: ISO C++20 considers use of overloaded operator '!=' (with operand types 'KeyGen' (aka '(anonymous namespace)::StandardKeyGen') and 'KeyGen') to be ambiguou s despite there being a unique best viable function with non-reversed arguments [-Werror,-Wambiguous-reversed-operator] while (cur != batch_end) { ~~~ ^ ~~~~~~~~~ util/ribbon_test.cc:111:8: note: candidate function with non-reversed arguments bool operator!=(const StandardKeyGen& other) { ^ util/ribbon_test.cc:107:8: note: ambiguous candidate function with reversed arguments bool operator==(const StandardKeyGen& other) { ^ ``` This will become a hard error in future standards. Confirmed that no errors were generated when building using clang and c++20: ``` USE_CLANG=1 USE_COROUTINES=1 make ``` Pull Request resolved: facebook#11371 Reviewed By: meyering Differential Revision: D44921027 Pulled By: cbi42 fbshipit-source-id: ef25b78260920a4d75a718310688d3a2487ffa87
1 parent 647cd73 commit 6b67b56

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ endif
539539

540540
ifdef USE_CLANG
541541
# Used by some teams in Facebook
542-
WARNING_FLAGS += -Wshift-sign-overflow
542+
WARNING_FLAGS += -Wshift-sign-overflow -Wambiguous-reversed-operator
543543
endif
544544

545545
ifeq ($(PLATFORM), OS_OPENBSD)

util/ribbon_test.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ struct StandardKeyGen {
104104
return str_;
105105
}
106106

107-
bool operator==(const StandardKeyGen& other) {
107+
bool operator==(const StandardKeyGen& other) const {
108108
// Same prefix is assumed
109109
return id_ == other.id_;
110110
}
111-
bool operator!=(const StandardKeyGen& other) {
111+
bool operator!=(const StandardKeyGen& other) const {
112112
// Same prefix is assumed
113113
return id_ != other.id_;
114114
}
@@ -144,8 +144,8 @@ struct SmallKeyGen {
144144
return str_;
145145
}
146146

147-
bool operator==(const SmallKeyGen& other) { return id_ == other.id_; }
148-
bool operator!=(const SmallKeyGen& other) { return id_ != other.id_; }
147+
bool operator==(const SmallKeyGen& other) const { return id_ == other.id_; }
148+
bool operator!=(const SmallKeyGen& other) const { return id_ != other.id_; }
149149

150150
uint64_t id_;
151151
std::string str_;
@@ -1069,11 +1069,11 @@ struct PhsfInputGen {
10691069

10701070
const std::pair<std::string, uint8_t>* operator->() { return &**this; }
10711071

1072-
bool operator==(const PhsfInputGen& other) {
1072+
bool operator==(const PhsfInputGen& other) const {
10731073
// Same prefix is assumed
10741074
return id_ == other.id_;
10751075
}
1076-
bool operator!=(const PhsfInputGen& other) {
1076+
bool operator!=(const PhsfInputGen& other) const {
10771077
// Same prefix is assumed
10781078
return id_ != other.id_;
10791079
}

0 commit comments

Comments
 (0)