Skip to content

Commit e2cacb7

Browse files
Fix the incompatibility with Clang and C++20 (#408)
### 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.
1 parent 6e1ad17 commit e2cacb7

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

.github/workflows/ci-pr-validation.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ jobs:
289289
timeout-minutes: 120
290290
name: Build CPP Client on macOS
291291
runs-on: macos-12
292-
needs: unit-tests
293292
steps:
294293
- name: checkout
295294
uses: actions/checkout@v3
@@ -306,6 +305,12 @@ jobs:
306305
run: |
307306
cmake --build ./build-macos --parallel --config Release
308307
308+
- name: Build with C++20
309+
shell: bash
310+
run: |
311+
cmake -B build-macos-cpp20 -DCMAKE_CXX_STANDARD=20
312+
cmake --build build-macos-cpp20 -j8
313+
309314
cpp-build-macos-static:
310315
timeout-minutes: 120
311316
name: Build CPP Client on macOS with static dependencies

lib/NamespaceName.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ std::shared_ptr<NamespaceName> NamespaceName::getNamespaceObject() {
9393
return std::shared_ptr<NamespaceName>(this);
9494
}
9595

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

lib/NamespaceName.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PULSAR_PUBLIC NamespaceName : public ServiceUnitId {
3737
static std::shared_ptr<NamespaceName> get(const std::string& property, const std::string& cluster,
3838
const std::string& namespaceName);
3939
static std::shared_ptr<NamespaceName> get(const std::string& property, const std::string& namespaceName);
40-
bool operator==(const NamespaceName& namespaceName);
40+
bool operator==(const NamespaceName& namespaceName) const;
4141
bool isV2();
4242
std::string toString();
4343

lib/TopicName.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ std::string TopicName::getLocalName() { return localName_; }
164164

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

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

lib/TopicName.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class PULSAR_PUBLIC TopicName : public ServiceUnitId {
6565
NamespaceNamePtr getNamespaceName();
6666
int getPartitionIndex() const noexcept { return partition_; }
6767
static std::shared_ptr<TopicName> get(const std::string& topicName);
68-
bool operator==(const TopicName& other);
68+
bool operator==(const TopicName& other) const;
6969
static std::string getEncodedName(const std::string& nameBeforeEncoding);
7070
static std::string removeDomain(const std::string& topicName);
7171
static bool containsDomain(const std::string& topicName);

0 commit comments

Comments
 (0)