From bd1e85eb8794b55b38f8a61bf46d6ee3620057b0 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Fri, 8 Sep 2023 17:48:03 +0800 Subject: [PATCH] Fix the visibility compilation error for GCC <= 7 ### Motivation https://github.com/apache/pulsar-client-cpp/pull/296 introduced a regression for GCC <= 7. > lib/RetryableOperation.h:109:66: error: 'pulsar::RetryableOperation::runImpl(pulsar::TimeDuration):: [with T = pulsar::LookupService::LookupResult]::' declared with greater visibility than the type of its field 'pulsar::RetryableOperation::runImpl(pulsar::TimeDuration):: [with T = pulsar::LookupService::LookupResult]::::' [-Werror=attributes] It seems to be a bug for GCC <= 7 abort the visibility of the lambda expression might not be affected by the `-fvisibility=hidden` option. ### Modifications Add `__attribute__((visibility("hidden")))` to `RetryableOperation::runImpl` explicitly. --- lib/RetryableOperation.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/RetryableOperation.h b/lib/RetryableOperation.h index 8a7b4710..8bebb5b0 100644 --- a/lib/RetryableOperation.h +++ b/lib/RetryableOperation.h @@ -79,7 +79,12 @@ class RetryableOperation : public std::enable_shared_from_this runImpl(TimeDuration remainingTime) { + // Fix the "declared with greater visibility" error for GCC <= 7 +#ifdef __GNUC__ + __attribute__((visibility("hidden"))) +#endif + Future + runImpl(TimeDuration remainingTime) { std::weak_ptr> weakSelf{this->shared_from_this()}; func_().addListener([this, weakSelf, remainingTime](Result result, const T& value) { auto self = weakSelf.lock();