From e55e2b27bfec1947c3258b8c2ab868ee8c33c646 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 14 Nov 2023 23:29:10 -0600 Subject: [PATCH] just upgrade GoogleTest and go to C++14 --- CMakeLists.txt | 11 ++++++----- include/LightGBM/utils/common.h | 12 +++++------- src/io/dense_bin.hpp | 2 +- src/io/multi_val_dense_bin.hpp | 5 +---- src/io/multi_val_sparse_bin.hpp | 4 ++-- src/io/sparse_bin.hpp | 2 +- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7616c15499c8..d617021c6772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,12 @@ endif() project(lightgbm LANGUAGES C CXX) +if(BUILD_CPP_TEST) + set(CMAKE_CXX_STANDARD 14) +else() + set(CMAKE_CXX_STANDARD 11) +endif() + list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") #-- Sanitizer @@ -327,11 +333,6 @@ if(${MM_MALLOC}) endif() if(UNIX OR MINGW OR CYGWIN) - if(BUILD_CPP_TEST) - set(CMAKE_CXX_STANDARD 20) - else() - set(CMAKE_CXX_STANDARD 11) - endif() set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wextra -Wall -Wno-ignored-attributes -Wno-unknown-pragmas -Wno-return-type" diff --git a/include/LightGBM/utils/common.h b/include/LightGBM/utils/common.h index d11f77253042..f1b5a10b5a69 100644 --- a/include/LightGBM/utils/common.h +++ b/include/LightGBM/utils/common.h @@ -1197,11 +1197,9 @@ inline static std::vector StringToArray(const std::string& str, char delimite * This safety check serves to prevent incorrect internal API usage. * Correct usage will never incur in this problem: * - The received buffer size shall be sufficient at all times for the input format string and value. -* /Users/jlamb/repos/LightGBM/include/LightGBM/utils/common.h:1203:35: in 'constexpr' expansion of 'fmt::v8::basic_format_string(format)' -* /Users/jlamb/repos/LightGBM/include/LightGBM/utils/common.h:1203:35: error: 'format' is not a constant expression */ template -inline static void format_to_buf(char* buffer, const size_t buf_len, fmt::format_string format, const T value) { +inline static void format_to_buf(char* buffer, const size_t buf_len, const char* format, const T value) { auto result = fmt::format_to_n(buffer, buf_len, format, value); if (result.size >= buf_len) { Log::Fatal("Numerical conversion failed. Buffer is too small."); @@ -1212,21 +1210,21 @@ inline static void format_to_buf(char* buffer, const size_t buf_len, fmt::format template struct __TToStringHelper { void operator()(T value, char* buffer, size_t buf_len) const { - format_to_buf(buffer, buf_len, fmt::format_string("{}"), value); + format_to_buf(buffer, buf_len, "{}", value); } }; template struct __TToStringHelper { void operator()(T value, char* buffer, size_t buf_len) const { - format_to_buf(buffer, buf_len, fmt::format_string("{:g}"), value); + format_to_buf(buffer, buf_len, "{:g}", value); } }; template struct __TToStringHelper { void operator()(T value, char* buffer, size_t buf_len) const { - format_to_buf(buffer, buf_len, fmt::format_string("{:.17g}"), value); + format_to_buf(buffer, buf_len, "{:.17g}", value); } }; @@ -1234,7 +1232,7 @@ struct __TToStringHelper { * Converts an array to a string with with values separated by the space character. * This method replaces Common's ``ArrayToString`` and ``ArrayToStringFast`` functionality * and is locale-independent. -* +* * \note If ``high_precision_output`` is set to true, * floating point values are output with more digits of precision. */ diff --git a/src/io/dense_bin.hpp b/src/io/dense_bin.hpp index 039ca99e77b8..e612052e47d2 100644 --- a/src/io/dense_bin.hpp +++ b/src/io/dense_bin.hpp @@ -614,7 +614,7 @@ class DenseBin : public Bin { #endif std::vector buf_; - DenseBin(const DenseBin& other) + DenseBin(const DenseBin& other) : num_data_(other.num_data_), data_(other.data_) {} }; diff --git a/src/io/multi_val_dense_bin.hpp b/src/io/multi_val_dense_bin.hpp index 5e356f796173..2bab45f044cd 100644 --- a/src/io/multi_val_dense_bin.hpp +++ b/src/io/multi_val_dense_bin.hpp @@ -343,10 +343,7 @@ class MultiValDenseBin : public MultiValBin { std::vector offsets_; std::vector> data_; - // https://oleksandrkvl.github.io/2021/04/02/cpp-20-overview.html - // https://github.com/PixarAnimationStudios/OpenUSD/issues/2183 - // https://github.com/PixarAnimationStudios/OpenUSD/pull/2242/files - MultiValDenseBin(const MultiValDenseBin& other) + MultiValDenseBin(const MultiValDenseBin& other) : num_data_(other.num_data_), num_bin_(other.num_bin_), num_feature_(other.num_feature_), offsets_(other.offsets_), data_(other.data_) { } diff --git a/src/io/multi_val_sparse_bin.hpp b/src/io/multi_val_sparse_bin.hpp index ee05e5cbd83e..edc48ca84c2a 100644 --- a/src/io/multi_val_sparse_bin.hpp +++ b/src/io/multi_val_sparse_bin.hpp @@ -430,8 +430,8 @@ class MultiValSparseBin : public MultiValBin { std::vector t_size_; std::vector offsets_; - MultiValSparseBin( - const MultiValSparseBin& other) + MultiValSparseBin( + const MultiValSparseBin& other) : num_data_(other.num_data_), num_bin_(other.num_bin_), estimate_element_per_row_(other.estimate_element_per_row_), diff --git a/src/io/sparse_bin.hpp b/src/io/sparse_bin.hpp index 799bb745223a..f7137d29ffd9 100644 --- a/src/io/sparse_bin.hpp +++ b/src/io/sparse_bin.hpp @@ -782,7 +782,7 @@ class SparseBin : public Bin { SparseBin* Clone() override; - SparseBin(const SparseBin& other) + SparseBin(const SparseBin& other) : num_data_(other.num_data_), deltas_(other.deltas_), vals_(other.vals_),