Skip to content

Commit

Permalink
Fix the incompatibility with Clang and C++20 (apache#408)
Browse files Browse the repository at this point in the history
### Motivation

When I built with Clang and C++20, there were the following errors:

> ISO C++20 considers use of overloaded operator '==' (with operand types 'pulsar::NamespaceName' and 'pulsar::NamespaceName') to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator]

See the detailed answer here: https://stackoverflow.com/questions/60386792/c20-comparison-warning-about-ambiguous-reversed-operator

### Modifications

Make the member functions of `operator=` const in `TopicName` and `NamespaceName` and add a workflow to cover this case.
  • Loading branch information
BewareMyPower authored Mar 3, 2024
1 parent 6e1ad17 commit e2cacb7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci-pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ jobs:
timeout-minutes: 120
name: Build CPP Client on macOS
runs-on: macos-12
needs: unit-tests
steps:
- name: checkout
uses: actions/checkout@v3
Expand All @@ -306,6 +305,12 @@ jobs:
run: |
cmake --build ./build-macos --parallel --config Release
- name: Build with C++20
shell: bash
run: |
cmake -B build-macos-cpp20 -DCMAKE_CXX_STANDARD=20
cmake --build build-macos-cpp20 -j8
cpp-build-macos-static:
timeout-minutes: 120
name: Build CPP Client on macOS with static dependencies
Expand Down
2 changes: 1 addition & 1 deletion lib/NamespaceName.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ std::shared_ptr<NamespaceName> NamespaceName::getNamespaceObject() {
return std::shared_ptr<NamespaceName>(this);
}

bool NamespaceName::operator==(const NamespaceName& namespaceName) {
bool NamespaceName::operator==(const NamespaceName& namespaceName) const {
return this->namespace_.compare(namespaceName.namespace_) == 0;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/NamespaceName.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PULSAR_PUBLIC NamespaceName : public ServiceUnitId {
static std::shared_ptr<NamespaceName> get(const std::string& property, const std::string& cluster,
const std::string& namespaceName);
static std::shared_ptr<NamespaceName> get(const std::string& property, const std::string& namespaceName);
bool operator==(const NamespaceName& namespaceName);
bool operator==(const NamespaceName& namespaceName) const;
bool isV2();
std::string toString();

Expand Down
2 changes: 1 addition & 1 deletion lib/TopicName.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ std::string TopicName::getLocalName() { return localName_; }

std::string TopicName::getEncodedLocalName() const { return getEncodedName(localName_); }

bool TopicName::operator==(const TopicName& other) {
bool TopicName::operator==(const TopicName& other) const {
return (this->topicName_.compare(other.topicName_) == 0);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/TopicName.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PULSAR_PUBLIC TopicName : public ServiceUnitId {
NamespaceNamePtr getNamespaceName();
int getPartitionIndex() const noexcept { return partition_; }
static std::shared_ptr<TopicName> get(const std::string& topicName);
bool operator==(const TopicName& other);
bool operator==(const TopicName& other) const;
static std::string getEncodedName(const std::string& nameBeforeEncoding);
static std::string removeDomain(const std::string& topicName);
static bool containsDomain(const std::string& topicName);
Expand Down

0 comments on commit e2cacb7

Please sign in to comment.