Skip to content

Commit ce325f6

Browse files
committed
Fix all compiler warnings in thread_system build
- Fix sign conversion warnings in convert_string.cpp by adding explicit casts - Fix constructor initialization order warnings in multiple files: - callback_job.cpp: Reorder member initialization to match declaration order - thread_base.cpp: Reorder wake_interval_ initialization - message_job.cpp: Fix member initialization order - file_writer.cpp: Correct initialization sequence - log_job.cpp: Match declaration order for message type members - log_collector.cpp: Fix queue and log type initialization order - thread_worker.cpp: Reorder use_time_tag_ and job_queue_ initialization - thread_pool.cpp: Fix start_pool_ and job_queue_ initialization order - Fix redundant move warnings in file_writer.cpp by removing unnecessary std::move - Fix sign conversion warnings in file_writer.cpp with explicit streamsize casts - Suppress duplicate library warnings on macOS with -Wl,-no_warn_duplicate_libraries flag
1 parent 2036325 commit ce325f6

10 files changed

Lines changed: 24 additions & 24 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
4848

4949
# Add additional flags for macOS
5050
if(APPLE)
51-
# Add linker flag to avoid duplicate library warnings on macOS
52-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-warn_duplicate_libraries")
51+
# Suppress duplicate library warnings on macOS (common with vcpkg)
52+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_warn_duplicate_libraries")
5353
endif()
5454
elseif(MSVC)
5555
# For Microsoft Visual C++ compiler

sources/logger/file_writer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ namespace log_module
4545
{
4646
file_writer::file_writer(void)
4747
: thread_base("file_writer")
48-
, job_queue_(std::make_shared<job_queue>())
4948
, title_("log")
5049
, use_backup_(false)
50+
, file_target_(log_types::None)
5151
, max_lines_(0)
5252
, log_file_(nullptr)
5353
, backup_file_(nullptr)
54-
, file_target_(log_types::None)
54+
, job_queue_(std::make_shared<job_queue>())
5555
{
5656
}
5757

@@ -159,7 +159,7 @@ namespace log_module
159159
backup_name_, std::ios_base::out | std::ios_base::app);
160160
}
161161

162-
std::deque<std::string> backup_lines(log_lines_.begin(), log_lines_.begin() + index);
162+
std::deque<std::string> backup_lines(log_lines_.begin(), log_lines_.begin() + static_cast<std::deque<std::string>::difference_type>(index));
163163

164164
if (backup_file_ && backup_file_->is_open())
165165
{
@@ -168,7 +168,7 @@ namespace log_module
168168
}
169169
}
170170

171-
log_lines_.erase(log_lines_.begin(), log_lines_.begin() + index);
171+
log_lines_.erase(log_lines_.begin(), log_lines_.begin() + static_cast<std::deque<std::string>::difference_type>(index));
172172

173173
log_file_ = write_lines(std::move(log_file_), log_lines_);
174174
log_file_->close();
@@ -267,16 +267,16 @@ namespace log_module
267267
{
268268
if (file_handle == nullptr || !file_handle->is_open())
269269
{
270-
return std::move(file_handle);
270+
return file_handle;
271271
}
272272

273273
for (const auto& message : messages)
274274
{
275-
file_handle->write(message.c_str(), message.size());
275+
file_handle->write(message.c_str(), static_cast<std::streamsize>(message.size()));
276276
}
277277

278278
file_handle->flush();
279279

280-
return std::move(file_handle);
280+
return file_handle;
281281
}
282282
}

sources/logger/log_collector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ namespace log_module
3838
{
3939
log_collector::log_collector(void)
4040
: thread_base("log_collector")
41-
, log_queue_(std::make_shared<job_queue>())
4241
, file_log_type_(log_types::None)
4342
, console_log_type_(log_types::None)
4443
, callback_log_type_(log_types::None)
44+
, log_queue_(std::make_shared<job_queue>())
4545
{
4646
}
4747

sources/logger/log_job.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ namespace log_module
5252
std::optional<log_types> type,
5353
std::optional<std::chrono::time_point<std::chrono::high_resolution_clock>> start_time)
5454
: job("log_job")
55-
, type_(type)
5655
, message_type_(message_types::String)
5756
, message_(message)
57+
, log_message_("")
58+
, type_(type)
5859
, timestamp_(std::chrono::system_clock::now())
5960
, start_time_(start_time)
60-
, log_message_("")
6161
{
6262
}
6363

@@ -66,12 +66,12 @@ namespace log_module
6666
std::optional<log_types> type,
6767
std::optional<std::chrono::time_point<std::chrono::high_resolution_clock>> start_time)
6868
: job("log_job")
69-
, type_(type)
7069
, message_type_(message_types::WString)
7170
, wmessage_(message)
71+
, log_message_("")
72+
, type_(type)
7273
, timestamp_(std::chrono::system_clock::now())
7374
, start_time_(start_time)
74-
, log_message_("")
7575
{
7676
}
7777

sources/logger/message_job.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace log_module
4141
message_job::message_job(const log_types& log_type,
4242
const std::string& datetime,
4343
const std::string& message)
44-
: job("message_job"), log_type_(log_type), datetime_(datetime), message_(message)
44+
: job("message_job"), datetime_(datetime), message_(message), log_type_(log_type)
4545
{
4646
}
4747

sources/thread_base/callback_job.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ namespace thread_module
5151
callback_job::callback_job(
5252
const std::function<std::optional<std::string>(const std::vector<uint8_t>&)>& data_callback,
5353
const std::vector<uint8_t>& data, const std::string& name)
54-
: job(data, name), data_callback_([data_callback](const std::vector<uint8_t>& data) -> result_void {
54+
: job(data, name), callback_(nullptr), data_callback_([data_callback](const std::vector<uint8_t>& data) -> result_void {
5555
auto result = data_callback(data);
5656
if (result.has_value()) {
5757
return error{error_code::job_execution_failed, result.value()};
5858
}
5959
return result_void{};
60-
}), callback_(nullptr)
60+
})
6161
{
6262
}
6363

sources/thread_base/thread_base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ namespace thread_module
5555
* - Sets initial thread_condition_ to Created
5656
*/
5757
thread_base::thread_base(const std::string& thread_title)
58-
: worker_thread_(nullptr)
58+
: wake_interval_(std::nullopt)
59+
, worker_thread_(nullptr)
5960
#ifdef USE_STD_JTHREAD
6061
, stop_source_(std::nullopt)
6162
#else
6263
, stop_requested_(false)
6364
#endif
64-
, wake_interval_(std::nullopt)
6565
, thread_title_(thread_title)
6666
, thread_condition_(thread_conditions::Created)
6767
{

sources/thread_pool/thread_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ using namespace utility_module;
4040
namespace thread_pool_module
4141
{
4242
thread_pool::thread_pool(const std::string& thread_title)
43-
: thread_title_(thread_title), job_queue_(std::make_shared<job_queue>()), start_pool_(false)
43+
: thread_title_(thread_title), start_pool_(false), job_queue_(std::make_shared<job_queue>())
4444
{
4545
}
4646

sources/thread_pool/thread_worker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
namespace thread_pool_module
3939
{
4040
thread_worker::thread_worker(const bool& use_time_tag)
41-
: thread_base("thread_worker"), job_queue_(nullptr), use_time_tag_(use_time_tag)
41+
: thread_base("thread_worker"), use_time_tag_(use_time_tag), job_queue_(nullptr)
4242
{
4343
}
4444

sources/utilities/convert_string.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ namespace utility_module
452452
int mod_table[] = { 0, 2, 1 };
453453
for (int j = 0; j < mod_table[data.size() % 3]; j++)
454454
{
455-
encoded_string[encoded_string.size() - 1 - j] = '=';
455+
encoded_string[encoded_string.size() - 1 - static_cast<size_t>(j)] = '=';
456456
}
457457

458458
return encoded_string;
@@ -490,7 +490,7 @@ namespace utility_module
490490
std::vector<int> decoding_table(256, -1);
491491
for (int i = 0; i < 64; i++)
492492
{
493-
decoding_table[static_cast<unsigned char>(base64_chars[i])] = i;
493+
decoding_table[static_cast<unsigned char>(base64_chars[static_cast<size_t>(i)])] = i;
494494
}
495495

496496
uint32_t buffer = 0;
@@ -513,7 +513,7 @@ namespace utility_module
513513
return { std::vector<uint8_t>(), "Invalid character in base64 string" };
514514
}
515515

516-
buffer = (buffer << 6) | decoding_table[static_cast<unsigned char>(c)];
516+
buffer = (buffer << 6) | static_cast<uint32_t>(decoding_table[static_cast<unsigned char>(c)]);
517517
bits_collected += 6;
518518

519519
if (bits_collected >= 8)

0 commit comments

Comments
 (0)