Skip to content

Commit

Permalink
Workaround for gcc-11.4/draft 2x spec flaw (#4679)
Browse files Browse the repository at this point in the history
- A late draft of the C++2x spec introduced a non-backwards compatible
  change in the way overloading for operator ==/!= is handled; this was
  considered a defect and was fix in the final C++20 spec.
  • Loading branch information
ChrisDodd authored May 30, 2024
1 parent 8ff79b8 commit 90e90e6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ir/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ struct ID : Util::IHasSourceInfo {
}
bool operator==(const ID &a) const { return name == a.name; }
bool operator!=(const ID &a) const { return name != a.name; }
bool operator==(cstring a) const { return name == a; }
bool operator!=(cstring a) const { return name != a; }
bool operator==(const char *a) const { return name == a; }
bool operator!=(const char *a) const { return name != a; }
explicit operator bool() const { return name; }
operator cstring() const { return name; }
bool isDontCare() const { return name == "_"; }
Expand Down
2 changes: 1 addition & 1 deletion ir/namemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class NameMap : public Node {
}

IRNODE_SUBCLASS(NameMap)
bool operator==(const Node &a) const override { return a == *this; }
bool operator==(const Node &a) const override { return a.operator==(*this); }
bool operator==(const NameMap &a) const { return symbols == a.symbols; }
bool equiv(const Node &a_) const override {
if (static_cast<const Node *>(this) == &a_) return true;
Expand Down
3 changes: 3 additions & 0 deletions lib/cstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class cstring {
bool operator==(cstring a) const { return str == a.str; }
bool operator!=(cstring a) const { return str != a.str; }

bool operator==(std::nullptr_t) const { return str == nullptr; }
bool operator!=(std::nullptr_t) const { return str != nullptr; }

// Other comparisons and tests. Linear time.
bool operator==(const char *a) const { return str ? a && !strcmp(str, a) : !a; }
bool operator!=(const char *a) const { return str ? !a || !!strcmp(str, a) : !!a; }
Expand Down

0 comments on commit 90e90e6

Please sign in to comment.