From 3e88939500612e9f7c9bf1ebf20609557e55242f Mon Sep 17 00:00:00 2001 From: Senichenkov Date: Wed, 27 Nov 2024 19:44:19 +0300 Subject: [PATCH] Use macro instead of [[maybe_unsued]] Use macro that works both for clang and g++ instead of [[maybe_unused]] (because g++ produces a warning when [[maybe_unsued]] is present, and clang -- when isn't) --- .../fd/pyrocommon/model/pli_cache.h | 19 ++++++++++--------- src/core/model/table/vertical_map.cpp | 5 +++-- src/core/util/maybe_unused.h | 10 ++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 src/core/util/maybe_unused.h diff --git a/src/core/algorithms/fd/pyrocommon/model/pli_cache.h b/src/core/algorithms/fd/pyrocommon/model/pli_cache.h index 61c0214ec3..90061da3cd 100644 --- a/src/core/algorithms/fd/pyrocommon/model/pli_cache.h +++ b/src/core/algorithms/fd/pyrocommon/model/pli_cache.h @@ -8,6 +8,7 @@ class ProfilingContext; #include "cache_eviction_method.h" #include "caching_method.h" #include "model/table/column_layout_relation_data.h" +#include "util/maybe_unused.h" namespace model { @@ -29,20 +30,20 @@ class PLICache { std::unique_ptr> index_; // usageCounter - for parallelism - // int saved_intersections_ = 0; + MAYBE_UNUSED int saved_intersections_ = 0; mutable std::mutex getting_pli_mutex_; CachingMethod caching_method_; - [[maybe_unused]] CacheEvictionMethod eviction_method_; - [[maybe_unused]] double caching_method_value_; - [[maybe_unused]] long long maximumAvailableMemory_ = 0; + MAYBE_UNUSED CacheEvictionMethod eviction_method_; + MAYBE_UNUSED double caching_method_value_; + // long long maximumAvailableMemory_ = 0; double maximum_entropy_; - [[maybe_unused]] double mean_entropy_; - [[maybe_unused]] double min_entropy_; - [[maybe_unused]] double median_entropy_; - [[maybe_unused]] double median_gini_; - [[maybe_unused]] double median_inverted_entropy_; + MAYBE_UNUSED double mean_entropy_; + MAYBE_UNUSED double min_entropy_; + MAYBE_UNUSED double median_entropy_; + MAYBE_UNUSED double median_gini_; + MAYBE_UNUSED double median_inverted_entropy_; std::variant> CachingProcess( Vertical const& vertical, std::unique_ptr pli, diff --git a/src/core/model/table/vertical_map.cpp b/src/core/model/table/vertical_map.cpp index f24234bf6e..22757fc060 100644 --- a/src/core/model/table/vertical_map.cpp +++ b/src/core/model/table/vertical_map.cpp @@ -8,6 +8,7 @@ #include "fd/pyrocommon/core/vertical_info.h" #include "fd/pyrocommon/model/agree_set_sample.h" #include "position_list_index.h" +#include "util/maybe_unused.h" namespace model { @@ -425,7 +426,7 @@ void VerticalMap::Shrink(double factor, std::function key_queue.push(entry); } }); - [[maybe_unused]] unsigned int num_of_removed = 0; + MAYBE_UNUSED unsigned int num_of_removed = 0; unsigned int target_size = size_ * factor; while (!key_queue.empty() && size_ > target_size) { auto key = key_queue.top().first; @@ -467,7 +468,7 @@ void VerticalMap::Shrink(std::unordered_map& usag key_queue.push(entry); } }); - [[maybe_unused]] unsigned int num_of_removed = 0; + MAYBE_UNUSED unsigned int num_of_removed = 0; while (!key_queue.empty()) { auto key = key_queue.front().first; key_queue.pop(); diff --git a/src/core/util/maybe_unused.h b/src/core/util/maybe_unused.h new file mode 100644 index 0000000000..9a79e1167b --- /dev/null +++ b/src/core/util/maybe_unused.h @@ -0,0 +1,10 @@ +#pragma once + +// clang produces warning on unused private fields, so they need to be marked as [[maybe_unused]], +// but g++ doesn't recognize [[maybe_unused]] on class fields and produces warning. +// This macro expands to [[maybe_unsued]], when compiler is clang, nop otherwise +#ifdef __clang__ +#define MAYBE_UNUSED [[maybe_unused]] +#else +#define MAYBE_UNUSED /* Ignore */ +#endif