From 85dd8bc10fcc521b38912a5d50af932eff361934 Mon Sep 17 00:00:00 2001 From: erick-alcachofa Date: Sat, 10 May 2025 21:07:49 -0600 Subject: [PATCH] chore: Added compile warnings Enabled compilation warnings and solved compilation problems. TODO: Is it correct to have the warnings `hard-coded` on the CMakeFiles? --- .clangd | 15 ++++++++++++++- frontend/CMakeLists.txt | 16 ++++++++++++++++ lib/CMakeLists.txt | 16 ++++++++++++++++ lib/src/Tokenizer/Token.cpp | 6 +++++- lib/src/Tokenizer/Tokenizer.cpp | 6 ++++-- lib/src/Util/Demangle.cpp | 3 ++- 6 files changed, 57 insertions(+), 5 deletions(-) diff --git a/.clangd b/.clangd index 1fd5e80..bb820dc 100644 --- a/.clangd +++ b/.clangd @@ -1,4 +1,17 @@ CompileFlags: - Add: [ -std=c++23 ] + Add: + - -pedantic + - -Wall + - -Wextra + - -Wold-style-cast + - -Wsign-conversion + - -Wsign-promo + - -Wstrict-null-sentinel + - -Wstrict-overflow=5 + - -Wswitch-default + - -Wundef + - -Werror + - -Wno-unused + - -std=c++23 Compiler: g++ CompilationDatabase: build diff --git a/frontend/CMakeLists.txt b/frontend/CMakeLists.txt index 69fce3c..2bacfdb 100644 --- a/frontend/CMakeLists.txt +++ b/frontend/CMakeLists.txt @@ -10,6 +10,22 @@ set_target_properties( OUTPUT_NAME "artichoke-c" ) +target_compile_options( + frontend PRIVATE + -pedantic + -Wall + -Wextra + -Wold-style-cast + -Wsign-conversion + -Wsign-promo + -Wstrict-null-sentinel + -Wstrict-overflow=5 + -Wswitch-default + -Wundef + -Werror + -Wno-unused +) + target_include_directories( frontend PUBLIC $ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 1d3cd30..99dc896 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -14,6 +14,22 @@ set_target_properties( OUTPUT_NAME "artichoke" ) +target_compile_options( + library PRIVATE + -pedantic + -Wall + -Wextra + -Wold-style-cast + -Wsign-conversion + -Wsign-promo + -Wstrict-null-sentinel + -Wstrict-overflow=5 + -Wswitch-default + -Wundef + -Werror + -Wno-unused +) + target_sources( library PUBLIC FILE_SET HEADERS diff --git a/lib/src/Tokenizer/Token.cpp b/lib/src/Tokenizer/Token.cpp index 9923869..9718b57 100644 --- a/lib/src/Tokenizer/Token.cpp +++ b/lib/src/Tokenizer/Token.cpp @@ -1,6 +1,7 @@ #include #include +#include namespace arti::lang { @@ -186,7 +187,10 @@ namespace arti::lang { return std::format("Token{{ {}, {} }}", "kwExport", value.strValue); case kwModule: return std::format("Token{{ {}, {} }}", "kwModule", value.strValue); + default: + return ""; } - return ""; + + std::unreachable(); } } // namespace arti::lang diff --git a/lib/src/Tokenizer/Tokenizer.cpp b/lib/src/Tokenizer/Tokenizer.cpp index b20f97d..9c1dd47 100644 --- a/lib/src/Tokenizer/Tokenizer.cpp +++ b/lib/src/Tokenizer/Tokenizer.cpp @@ -134,7 +134,10 @@ namespace arti::lang { } } - coret Token{ .value = TokenV::tkEOF, .line = line, .column = column }; + coret Token{ .value = TokenV::tkEOF, + .line = line, + .column = column, + .strValue = "" }; } void Tokenizer::skip_whitespace() { @@ -146,7 +149,6 @@ namespace arti::lang { column = 0; line += 1; break; - default: return; } diff --git a/lib/src/Util/Demangle.cpp b/lib/src/Util/Demangle.cpp index b52f444..6b2569b 100644 --- a/lib/src/Util/Demangle.cpp +++ b/lib/src/Util/Demangle.cpp @@ -16,7 +16,7 @@ namespace arti::lang { auto deallocator = [](char *mem) { if (mem) { - free((void *) mem); + free(static_cast(mem)); } }; @@ -44,6 +44,7 @@ namespace arti::lang { switch(ec) { case ecMemAlloc: return "Memory allocation failed"; case ecInvalid: return "Invalid argument"; + default: std::unreachable(); break; } std::unreachable();