diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index 91a93fcb..dde6e345 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -58,8 +58,8 @@ protected: void backend_flush_(); private: - std::weak_ptr thread_pool_; - async_overflow_policy overflow_policy_; + std::weak_ptr thread_pool_{}; + async_overflow_policy overflow_policy_{}; }; } // namespace spdlog diff --git a/include/spdlog/common.h b/include/spdlog/common.h index ed0ab46c..a31b523a 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -231,7 +231,7 @@ public: const char *what() const SPDLOG_NOEXCEPT override; private: - std::string msg_; + std::string msg_{}; }; [[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno); diff --git a/include/spdlog/details/backtracer.h b/include/spdlog/details/backtracer.h index b336ee77..550b3320 100644 --- a/include/spdlog/details/backtracer.h +++ b/include/spdlog/details/backtracer.h @@ -17,9 +17,9 @@ namespace spdlog { namespace details { class SPDLOG_API backtracer { - mutable std::mutex mutex_; + mutable std::mutex mutex_{}; std::atomic enabled_{false}; - circular_q messages_; + circular_q messages_{}; public: backtracer() = default; diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index 1f2712e7..0c83a385 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -16,7 +16,7 @@ class circular_q typename std::vector::size_type head_ = 0; typename std::vector::size_type tail_ = 0; size_t overrun_counter_ = 0; - std::vector v_; + std::vector v_{}; public: using value_type = T; diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index cfccaed2..c1d557be 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -49,7 +49,7 @@ private: const int open_tries_ = 5; const unsigned int open_interval_ = 10; std::FILE *fd_{nullptr}; - filename_t filename_; + filename_t filename_{}; }; } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/log_msg.h b/include/spdlog/details/log_msg.h index fed51abd..29b28338 100644 --- a/include/spdlog/details/log_msg.h +++ b/include/spdlog/details/log_msg.h @@ -17,17 +17,17 @@ struct SPDLOG_API log_msg log_msg(const log_msg &other) = default; log_msg &operator=(const log_msg &other) = default; - string_view_t logger_name; + string_view_t logger_name{}; level::level_enum level{level::off}; - log_clock::time_point time; + log_clock::time_point time{}; size_t thread_id{0}; // wrapping the formatted text with color (updated by pattern_formatter). mutable size_t color_range_start{0}; mutable size_t color_range_end{0}; - source_loc source; - string_view_t payload; + source_loc source{}; + string_view_t payload{}; }; } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/log_msg_buffer.h b/include/spdlog/details/log_msg_buffer.h index 81055065..12383791 100644 --- a/include/spdlog/details/log_msg_buffer.h +++ b/include/spdlog/details/log_msg_buffer.h @@ -13,7 +13,7 @@ namespace details { class SPDLOG_API log_msg_buffer : public log_msg { - memory_buf_t buffer; + memory_buf_t buffer{}; void update_string_views(); public: diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index 5c3cca76..bae954f1 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -117,10 +117,10 @@ public: } private: - std::mutex queue_mutex_; - std::condition_variable push_cv_; - std::condition_variable pop_cv_; - spdlog::details::circular_q q_; + std::mutex queue_mutex_{}; + std::condition_variable push_cv_{}; + std::condition_variable pop_cv_{}; + spdlog::details::circular_q q_{}; }; } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/null_mutex.h b/include/spdlog/details/null_mutex.h index 83533d4f..9cc730a1 100644 --- a/include/spdlog/details/null_mutex.h +++ b/include/spdlog/details/null_mutex.h @@ -21,7 +21,7 @@ struct null_mutex struct null_atomic_int { - int value; + int value{0}; null_atomic_int() = default; explicit null_atomic_int(int new_value) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 4602782c..a95b1c49 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -396,7 +396,7 @@ SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT #ifdef _WIN32 return static_cast(::GetCurrentProcessId()); #else - return static_cast(::getpid()); + return ::getpid(); #endif } diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index a300218d..2a57a3a2 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -27,10 +27,10 @@ public: ~periodic_worker(); private: - bool active_; - std::thread worker_thread_; - std::mutex mutex_; - std::condition_variable cv_; + bool active_{false}; + std::thread worker_thread_{}; + std::mutex mutex_{}; + std::condition_variable cv_{}; }; } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index c55b5eea..795ad591 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -31,7 +31,8 @@ namespace spdlog { namespace details { SPDLOG_INLINE registry::registry() - : formatter_(new pattern_formatter()) + : formatter_(new pattern_formatter()), + periodic_flusher_(nullptr) { #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 97473ea3..4ddb5b8c 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -92,17 +92,17 @@ private: void throw_if_exists_(const std::string &logger_name); void register_logger_(std::shared_ptr new_logger); bool set_level_from_cfg_(logger *logger); - std::mutex logger_map_mutex_, flusher_mutex_; - std::recursive_mutex tp_mutex_; - std::unordered_map> loggers_; - log_levels log_levels_; + std::mutex logger_map_mutex_{}, flusher_mutex_{}; + std::recursive_mutex tp_mutex_{}; + std::unordered_map> loggers_{}; + log_levels log_levels_{}; std::unique_ptr formatter_; spdlog::level::level_enum global_log_level_ = level::info; level::level_enum flush_level_ = level::off; - err_handler err_handler_; - std::shared_ptr tp_; + err_handler err_handler_{}; + std::shared_ptr tp_{}; std::unique_ptr periodic_flusher_; - std::shared_ptr default_logger_; + std::shared_ptr default_logger_{}; bool automatic_registration_ = true; size_t backtrace_n_messages_ = 0; }; diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 86187e40..3ad6202d 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -99,9 +99,9 @@ public: size_t queue_size(); private: - q_type q_; + q_type q_{0}; - std::vector threads_; + std::vector threads_{}; void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); void worker_loop_(); diff --git a/include/spdlog/fmt/bundled/core.h b/include/spdlog/fmt/bundled/core.h index b33293eb..35f1a80e 100644 --- a/include/spdlog/fmt/bundled/core.h +++ b/include/spdlog/fmt/bundled/core.h @@ -435,8 +435,8 @@ FMT_END_DETAIL_NAMESPACE */ template class basic_string_view { private: - const Char* data_; - size_t size_; + const Char* data_{nullptr}; + size_t size_{0}; public: using value_type = Char; @@ -619,8 +619,8 @@ template using char_t = typename detail::char_t_impl::type; template class basic_format_parse_context : private ErrorHandler { private: - basic_string_view format_str_; - int next_arg_id_; + basic_string_view format_str_{}; + int next_arg_id_{0}; public: using char_type = Char; @@ -748,9 +748,9 @@ FMT_CONSTEXPR auto copy_str(const Char* begin, const Char* end, Char* out) */ template class buffer { private: - T* ptr_; - size_t size_; - size_t capacity_; + T* ptr_{nullptr}; + size_t size_{0}; + size_t capacity_{0}; protected: // Don't initialize ptr_ since it is not accessed to save a few cycles. @@ -840,7 +840,7 @@ struct buffer_traits { class fixed_buffer_traits { private: size_t count_ = 0; - size_t limit_; + size_t limit_ = 0; public: explicit fixed_buffer_traits(size_t limit) : limit_(limit) {} @@ -856,9 +856,9 @@ class fixed_buffer_traits { template class iterator_buffer final : public Traits, public buffer { private: - OutputIt out_; + OutputIt out_ = {}; enum { buffer_size = 256 }; - T data_[buffer_size]; + T data_[buffer_size] = {}; protected: void grow(size_t) final FMT_OVERRIDE { @@ -924,7 +924,7 @@ class iterator_buffer, template class counting_buffer final : public buffer { private: enum { buffer_size = 256 }; - T data_[buffer_size]; + T data_[buffer_size]{}; size_t count_ = 0; protected: @@ -1385,8 +1385,8 @@ class appender : public std::back_insert_iterator> { // allow storage in basic_memory_buffer. template class basic_format_arg { private: - detail::value value_; - detail::type type_; + detail::value value_ = {}; + detail::type type_ = {}; template friend FMT_CONSTEXPR auto detail::make_arg(const T& value) @@ -1419,7 +1419,7 @@ template class basic_format_arg { } private: - detail::custom_value custom_; + detail::custom_value custom_{}; }; constexpr basic_format_arg() : type_(detail::type::none_type) {} @@ -1528,7 +1528,7 @@ struct is_contiguous_back_insert_iterator : std::true_type {}; // A type-erased reference to an std::locale to avoid heavy include. class locale_ref { private: - const void* locale_; // A type-erased pointer to std::locale. + const void* locale_{nullptr}; // A type-erased pointer to std::locale. public: constexpr locale_ref() : locale_(nullptr) {} @@ -1585,9 +1585,9 @@ template class basic_format_context { using char_type = Char; private: - OutputIt out_; - basic_format_args args_; - detail::locale_ref loc_; + OutputIt out_{}; + basic_format_args args_{}; + detail::locale_ref loc_{}; public: using iterator = OutputIt; @@ -1747,7 +1747,7 @@ template class basic_format_args { // If the number of arguments is less or equal to max_packed_args then // argument types are passed in the descriptor. This reduces binary code size // per formatting function call. - unsigned long long desc_; + unsigned long long desc_{0}; union { // If is_packed() returns true then argument values are stored in values_; // otherwise they are stored in args_. This is done to improve cache @@ -1876,6 +1876,7 @@ template struct fill_t { unsigned char size_ = 1; public: + // GCC's effective C++ warning mis-identifies this as an assignment // operator, and therefore recommends returning a reference to *this. #pragma GCC diagnostic push @@ -1919,7 +1920,8 @@ template struct basic_format_specs { align(align::none), sign(sign::none), alt(false), - localized(false) {} + localized(false), + fill() {} }; using format_specs = basic_format_specs; @@ -1958,8 +1960,8 @@ template struct arg_ref { // different sets of arguments (precompilation of format strings). template struct dynamic_format_specs : basic_format_specs { - arg_ref width_ref; - arg_ref precision_ref; + arg_ref width_ref{}; + arg_ref precision_ref{}; }; struct auto_id {}; @@ -2461,7 +2463,7 @@ template class compile_parse_context : public basic_format_parse_context { private: - int num_args_; + int num_args_{0}; using base = basic_format_parse_context; public: @@ -2599,7 +2601,7 @@ FMT_CONSTEXPR void check_pointer_type_spec(Char spec, ErrorHandler&& eh) { // the argument type. template class specs_checker : public Handler { private: - detail::type arg_type_; + detail::type arg_type_{}; FMT_CONSTEXPR void require_numeric_argument() { if (!is_arithmetic_type(arg_type_)) @@ -2686,7 +2688,7 @@ class format_string_checker { // Format specifier parsing function. using parse_func = const Char* (*)(parse_context_type&); - parse_context_type context_; + parse_context_type context_{}; parse_func parse_funcs_[num_args > 0 ? num_args : 1]; public: @@ -2757,7 +2759,7 @@ struct formatter::value != detail::type::custom_type>> { private: - detail::dynamic_format_specs specs_; + detail::dynamic_format_specs specs_{}; public: // Parses format specifiers stopping either at the end of the range or at the @@ -2834,7 +2836,7 @@ template struct basic_runtime { basic_string_view str; }; template class basic_format_string { private: - basic_string_view str_; + basic_string_view str_{}; public: template ; public: - significand_type f; - int e; + significand_type f{0}; + int e{0}; // All sizes are in bits. // Subtract 1 to account for an implicit most significant bit in the @@ -367,8 +367,8 @@ class bigint { using bigit = uint32_t; using double_bigit = uint64_t; enum { bigits_capacity = 32 }; - basic_memory_buffer bigits_; - int exp_; + basic_memory_buffer bigits_{}; + int exp_{0}; bigit operator[](int index) const { return bigits_[to_unsigned(index)]; } bigit& operator[](int index) { return bigits_[to_unsigned(index)]; } @@ -2524,7 +2524,7 @@ template <> struct formatter { } }; -FMT_FUNC detail::utf8_to_utf16::utf8_to_utf16(string_view s) { +FMT_FUNC detail::utf8_to_utf16::utf8_to_utf16(string_view s) : buffer_() { for_each_codepoint(s, [this](uint32_t cp, int error) { if (error != 0) FMT_THROW(std::runtime_error("invalid utf8")); if (cp <= 0xFFFF) { diff --git a/include/spdlog/fmt/bundled/format.h b/include/spdlog/fmt/bundled/format.h index 5398a23a..79fa6065 100644 --- a/include/spdlog/fmt/bundled/format.h +++ b/include/spdlog/fmt/bundled/format.h @@ -623,10 +623,10 @@ template > class basic_memory_buffer final : public detail::buffer { private: - T store_[SIZE]; + T store_[SIZE]{}; // Don't inherit from Allocator avoid generating type_info for it. - Allocator alloc_; + Allocator alloc_{}; // Deallocate memory allocated by the buffer. void deallocate() { @@ -2275,8 +2275,8 @@ class format_int { // Buffer should be large enough to hold all digits (digits10 + 1), // a sign and a null character. enum { buffer_size = std::numeric_limits::digits10 + 3 }; - mutable char buffer_[buffer_size]; - char* str_; + mutable char buffer_[buffer_size]{}; + char* str_{nullptr}; template auto format_unsigned(UInt value) -> char* { auto n = static_cast>(value); @@ -2401,8 +2401,8 @@ struct formatter : formatter, Char> { // }; template class dynamic_formatter { private: - detail::dynamic_format_specs specs_; - const Char* format_str_; + detail::dynamic_format_specs specs_{}; + const Char* format_str_{nullptr}; struct null_handler : detail::error_handler { void on_align(align_t) {} @@ -2461,7 +2461,7 @@ template auto ptr(const std::shared_ptr& p) -> const void* { class bytes { private: - string_view data_; + string_view data_{}; friend struct formatter; public: @@ -2470,7 +2470,7 @@ class bytes { template <> struct formatter { private: - detail::dynamic_format_specs specs_; + detail::dynamic_format_specs specs_{}; public: template diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index eea0afc2..2be690cb 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -316,12 +316,12 @@ public: virtual std::shared_ptr clone(std::string logger_name); protected: - std::string name_; - std::vector sinks_; + std::string name_{}; + std::vector sinks_{}; spdlog::level_t level_{level::info}; spdlog::level_t flush_level_{level::off}; err_handler custom_err_handler_{nullptr}; - details::backtracer tracer_; + details::backtracer tracer_{}; // common implementation for after templated public api has been resolved template diff --git a/include/spdlog/pattern_formatter-inl.h b/include/spdlog/pattern_formatter-inl.h index ec727032..b20cfb54 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -88,7 +88,7 @@ private: const padding_info &padinfo_; memory_buf_t &dest_; - long remaining_pad_; + long remaining_pad_ {0}; string_view_t spaces_{" ", 64}; }; @@ -704,7 +704,7 @@ public: } private: - char ch_; + char ch_ = 0; }; // aggregate user chars to display as is @@ -723,7 +723,7 @@ public: } private: - std::string str_; + std::string str_{}; }; // mark the color range. expect it to be in the form of "%^colored text%$" @@ -921,7 +921,7 @@ public: } private: - log_clock::time_point last_message_time_; + log_clock::time_point last_message_time_ = {}; }; // Full info formatter @@ -1009,7 +1009,7 @@ public: private: std::chrono::seconds cache_timestamp_{0}; - memory_buf_t cached_datetime_; + memory_buf_t cached_datetime_{}; }; } // namespace details diff --git a/include/spdlog/pattern_formatter.h b/include/spdlog/pattern_formatter.h index e9ccfaa7..240d9a62 100644 --- a/include/spdlog/pattern_formatter.h +++ b/include/spdlog/pattern_formatter.h @@ -58,7 +58,7 @@ public: virtual void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0; protected: - padding_info padinfo_; + padding_info padinfo_{}; }; } // namespace details @@ -100,13 +100,13 @@ public: void set_pattern(std::string pattern); private: - std::string pattern_; - std::string eol_; - pattern_time_type pattern_time_type_; - std::tm cached_tm_; - std::chrono::seconds last_log_secs_; - std::vector> formatters_; - custom_flags custom_handlers_; + std::string pattern_{}; + std::string eol_{}; + pattern_time_type pattern_time_type_{}; + std::tm cached_tm_ = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + std::chrono::seconds last_log_secs_{}; + std::vector> formatters_{}; + custom_flags custom_handlers_{}; std::tm get_time_(const details::log_msg &msg); template diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 39d966bc..4a6b9c22 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -80,11 +80,11 @@ public: const string_view_t bold_on_red = "\033[1m\033[41m"; private: - FILE *target_file_; - mutex_t &mutex_; - bool should_do_colors_; + FILE *target_file_{nullptr}; + mutex_t &mutex_{}; + bool should_do_colors_{false}; std::unique_ptr formatter_; - std::array colors_; + std::array colors_{}; void print_ccode_(const string_view_t &color_code); void print_range_(const memory_buf_t &formatted, size_t start, size_t end); static std::string to_string_(const string_view_t &sv); diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index 9b030fc1..11e2445c 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -40,11 +40,11 @@ public: protected: using mutex_t = typename ConsoleMutex::mutex_t; - void *out_handle_; - mutex_t &mutex_; - bool should_do_colors_; + void *out_handle_{nullptr}; + mutex_t &mutex_{}; + bool should_do_colors_{false}; std::unique_ptr formatter_; - std::array colors_; + std::array colors_{}; // set foreground color and return the orig console attributes (for resetting later) std::uint16_t set_foreground_color_(std::uint16_t attribs); diff --git a/include/spdlog/stopwatch.h b/include/spdlog/stopwatch.h index bb976b19..e2b6b6cc 100644 --- a/include/spdlog/stopwatch.h +++ b/include/spdlog/stopwatch.h @@ -28,7 +28,7 @@ namespace spdlog { class stopwatch { using clock = std::chrono::steady_clock; - std::chrono::time_point start_tp_; + std::chrono::time_point start_tp_{}; public: stopwatch()