You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xy...@apache.org on 2024/03/03 17:24:14 UTC
(pulsar-client-cpp) branch main updated: Fix the incompatibility with Clang and C++20 (#408)
This is an automated email from the ASF dual-hosted git repository.
xyz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new e2cacb7 Fix the incompatibility with Clang and C++20 (#408)
e2cacb7 is described below
commit e2cacb7dfb57b6d059b49fead2e1611548ff89b0
Author: Yunze Xu <xy...@163.com>
AuthorDate: Mon Mar 4 01:24:09 2024 +0800
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.
---
.github/workflows/ci-pr-validation.yaml | 7 ++++++-
lib/NamespaceName.cc | 2 +-
lib/NamespaceName.h | 2 +-
lib/TopicName.cc | 2 +-
lib/TopicName.h | 2 +-
5 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/.github/workflows/ci-pr-validation.yaml b/.github/workflows/ci-pr-validation.yaml
index 56309e9..61134aa 100644
--- a/.github/workflows/ci-pr-validation.yaml
+++ b/.github/workflows/ci-pr-validation.yaml
@@ -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
@@ -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
diff --git a/lib/NamespaceName.cc b/lib/NamespaceName.cc
index f493db2..d635480 100644
--- a/lib/NamespaceName.cc
+++ b/lib/NamespaceName.cc
@@ -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;
}
diff --git a/lib/NamespaceName.h b/lib/NamespaceName.h
index ce451a2..d1f5765 100644
--- a/lib/NamespaceName.h
+++ b/lib/NamespaceName.h
@@ -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();
diff --git a/lib/TopicName.cc b/lib/TopicName.cc
index 5b892fc..487eee5 100644
--- a/lib/TopicName.cc
+++ b/lib/TopicName.cc
@@ -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);
}
diff --git a/lib/TopicName.h b/lib/TopicName.h
index 8cc9cb5..bee8138 100644
--- a/lib/TopicName.h
+++ b/lib/TopicName.h
@@ -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);