This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 68947bb6a50d76e6147ee24c474058d3234311a7 Author: Brian Neradt <[email protected]> AuthorDate: Wed Mar 27 16:29:56 2024 -0500 Fix warnings from clang 18 (#11191) * Disable variable length array warnings clang 18 warns about the use of dynamic variables used as the size of arrays on the stack. We use this in a variety of places. I'm addressing this by simply disabling the warning for now since we have used these forever and my feel is that the community is OK with it. Some possible alternatives would be to use alloca or to move this memory to the heap via std::vector, but that, if desired, can be done in a separate patch. Example warning: src/api/InkAPI.cc:8421:16: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension] 8421 | char buf[sid->len * 2 + 1]; | ^~~~~~~~~~~~~~~~ src/api/InkAPI.cc:8421:16: note: read of non-constexpr variable 'sid' is not allowed in a constant expression src/api/InkAPI.cc:8420:27: note: declared here 8420 | const SSLSessionID *sid = reinterpret_cast<const SSLSessionID *>(session_id); | ^ * std::result_of -> std::invoke_result std::result_of has been deprecated since c++17 with users encouraged to move to std::invoke_result instead. clang 18 warns of this. This patch transitions us to the std::invoke_result API. Example warning: /usr/bin/../lib/gcc/aarch64-redhat-linux/14/../../../../include/c++/14/type_traits:2708:5: error: 'result_of<(lambda at plugins/experimental/txn_box/plugin/include/txn_box/common.h:223:71) (unsigned long)>' is deprecated: u se 'std::invoke_result' instead [-Werror,-Wdeprecated-declarations] 2708 | using result_of_t = typename result_of<_Tp>::type; | ^ plugins/experimental/txn_box/plugin/include/txn_box/common.h:204:26: note: in instantiation of template type alias 'result_of_t' requested here 204 | return std::array<std::result_of_t<GENERATOR(size_t)>, sizeof...(IDX)>{g(IDX)...}; | ^ * std::shared_ptr::unique -> std::shared_ptr::use_count std::shared_ptr::unique is deprecated since c++17 since it is approximate in multithreaded environments. The inliner plugin made use of unique. The one place that it used unique positively to reset data it does so under a lock, so that seems safe. The other use of unique was to compare !unique in such a way that seems flexible with the result being approximate anyway. So from my inspection, it seems safe to simply transition to use_count. (cherry picked from commit 4244856b8ee3d6b4a72c6a8d572d9f4ac9cf8dfd) --- CMakeLists.txt | 2 +- plugins/experimental/inliner/ts.cc | 4 ++-- plugins/experimental/txn_box/plugin/include/txn_box/common.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bb2148ee1..abe7209246 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -564,7 +564,7 @@ add_subdirectory(lib) # there are warnings, we can't do anything about it. # Note: -DCMAKE_COMPILE_WARNING_AS_ERROR=ON will turn warnings into errors. add_compile_options(-pipe -Wall -Wextra -Wno-unused-parameter) -add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-noexcept-type;-Wsuggest-override>") +add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-noexcept-type;-Wsuggest-override;-Wno-vla-extension>") add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-Wno-format-truncation;-Wno-stringop-overflow>") if(NOT EXTERNAL_YAML_CPP) diff --git a/plugins/experimental/inliner/ts.cc b/plugins/experimental/inliner/ts.cc index 7b26275d7a..b7d1a591de 100644 --- a/plugins/experimental/inliner/ts.cc +++ b/plugins/experimental/inliner/ts.cc @@ -307,7 +307,7 @@ namespace io const Node::Result result = data_->process(operation->buffer_); operation->bytes_ += result.first; operation->process(); - if (result.second && data_.unique()) { + if (result.second && data_.use_count() == 1) { data_.reset(); } } @@ -448,7 +448,7 @@ namespace io assert(*it != nullptr); const Node::Result result = (*it)->process(b); length += result.first; - if (!result.second || !it->unique()) { + if (!result.second || it->use_count() != 1) { break; } } diff --git a/plugins/experimental/txn_box/plugin/include/txn_box/common.h b/plugins/experimental/txn_box/plugin/include/txn_box/common.h index fd285652ca..166f1c9b66 100644 --- a/plugins/experimental/txn_box/plugin/include/txn_box/common.h +++ b/plugins/experimental/txn_box/plugin/include/txn_box/common.h @@ -198,10 +198,10 @@ indexed_init_list(GENERATOR &&g) } template <typename GENERATOR, size_t... IDX> -constexpr std::array<std::result_of_t<GENERATOR(size_t)>, sizeof...(IDX)> +constexpr std::array<std::invoke_result_t<GENERATOR, size_t>, sizeof...(IDX)> indexed_array(GENERATOR &&g, std::index_sequence<IDX...> &&) { - return std::array<std::result_of_t<GENERATOR(size_t)>, sizeof...(IDX)>{g(IDX)...}; + return std::array<std::invoke_result_t<GENERATOR, size_t>, sizeof...(IDX)>{g(IDX)...}; } template <size_t N, typename GENERATOR> constexpr std::array<std::result_of_t<GENERATOR(size_t)>, N>
