From d888b3e7f1fe60b8768932ff2ece0df8b108fbf5 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 14 Aug 2025 19:55:33 +0200 Subject: [PATCH] fix compilation on windows/LLVM --- include/Stl/format.hpp | 2 ++ modules/Language/VirtualMachine.mpp | 33 +++++++++++++++++------------ modules/Network/Socket.mpp | 7 +++++- modules/Terminal/Cursor.mpp | 6 +++--- modules/Terminal/Handle.mpp | 2 ++ modules/Terminal/TextModifier.mpp | 1 + tests/Container/DependencyGraph.mpp | 4 ++-- tests/Container/Stack.mpp | 16 +++++++------- tests/FileSystem/Watcher.mpp | 32 ++++++++++++++++++++++++++++ tests/Type/Tuple.mpp | 2 +- xmake.lua | 2 +- 11 files changed, 77 insertions(+), 30 deletions(-) diff --git a/include/Stl/format.hpp b/include/Stl/format.hpp index ebfd8b2c..b0b538b0 100644 --- a/include/Stl/format.hpp +++ b/include/Stl/format.hpp @@ -4,6 +4,8 @@ #include #include +#include + #if __has_include() # include diff --git a/modules/Language/VirtualMachine.mpp b/modules/Language/VirtualMachine.mpp index fbf6ffa7..d9079a31 100644 --- a/modules/Language/VirtualMachine.mpp +++ b/modules/Language/VirtualMachine.mpp @@ -97,7 +97,7 @@ export namespace CppUtils::Language::VirtualMachine case '#': if (auto startPosition = stack.template get(); not startPosition) [[unlikely]] return std::unexpected{startPosition.error()}; - else if (auto result = stack.set(std::hash{}(decltype(source){std::cbegin(source) + startPosition.value() + 1, std::cbegin(source) + position - 1})); not result) [[unlikely]] + else if (auto result = stack.set(std::hash{}(decltype(source){std::cbegin(source) + static_cast(startPosition.value() + 1), std::cbegin(source) + static_cast(position - 1)})); not result) [[unlikely]] return result; break; @@ -178,9 +178,9 @@ export namespace CppUtils::Language::VirtualMachine case '>': if (auto key = stack.template get(); not key) [[unlikely]] return std::unexpected{key.error()}; - else if (registers.contains(key.value())) [[likely]] - stack.set(registers[key.value()]); - else + else if (registers.contains(key.value())) [[likely]] { + auto _ = stack.set(registers[key.value()]); + } else return std::unexpected{"Unknown register key"sv}; break; @@ -253,46 +253,50 @@ export namespace CppUtils::Language::VirtualMachine case '\\': ++position; break; - case '!': + case '!': { if (auto result = stack.template get(); not result) [[unlikely]] return std::unexpected{result.error()}; else - stack.set(not result.value()); + auto _ = stack.set(not result.value()); break; + } - case '?': + case '?': { if (auto condition = stack.template get(sizeof(std::size_t)); not condition) [[unlikely]] return std::unexpected{condition.error()}; else if (auto newPosition = stack.template pop(); not newPosition) [[unlikely]] return std::unexpected{newPosition.error()}; else if (not condition.value()) position = newPosition.value(); - stack.drop(sizeof(std::size_t)); + auto _ = stack.drop(sizeof(std::size_t)); break; + } case 'X': return {}; - case '+': + case '+': { if (auto lhs = stack.template pop(); not lhs) [[unlikely]] return std::unexpected{lhs.error()}; else if (auto rhs = stack.template get(); not rhs) [[unlikely]] return std::unexpected{rhs.error()}; else - stack.set(lhs.value() + rhs.value()); + auto _ = stack.set(lhs.value() + rhs.value()); break; + } - case '-': + case '-': { if (auto lhs = stack.template pop(); not lhs) [[unlikely]] return std::unexpected{lhs.error()}; else if (auto rhs = stack.template get(); not rhs) [[unlikely]] return std::unexpected{rhs.error()}; else - stack.set(lhs.value() - rhs.value()); + auto _ = stack.set(lhs.value() - rhs.value()); break; + } case ',': stack.dump(); break; - case '\'': stack.set(source[++position]); break; + case '\'': { auto _ = stack.set(source[++position]); break; } default: if (instruction >= '0' and instruction <= '9') @@ -300,8 +304,9 @@ export namespace CppUtils::Language::VirtualMachine if (auto result = stack.template get(); not result) [[unlikely]] return std::unexpected{result.error()}; else - stack.set(result.value() * 10 + static_cast(instruction - '0')); + auto _ = stack.set(result.value() * 10 + static_cast(instruction - '0')); } + break; } return {}; diff --git a/modules/Network/Socket.mpp b/modules/Network/Socket.mpp index bf704d32..ee098477 100644 --- a/modules/Network/Socket.mpp +++ b/modules/Network/Socket.mpp @@ -364,7 +364,12 @@ export namespace CppUtils::Network auto data = T{}; for (auto totalBytesReceived = 0uz; totalBytesReceived < sizeof(T);) { - auto bytesReceived = ::recv(m_socket, reinterpret_cast(std::addressof(data)) + totalBytesReceived, sizeof(T) - totalBytesReceived, 0); +#if defined(OS_WINDOWS) + const auto size = static_cast(sizeof(T) - totalBytesReceived); +#else + const auto size = sizeof(T) - totalBytesReceived; +#endif + auto bytesReceived = ::recv(m_socket, reinterpret_cast(std::addressof(data)) + totalBytesReceived, size, 0); if (bytesReceived < 0) { #if defined(OS_WINDOWS) diff --git a/modules/Terminal/Cursor.mpp b/modules/Terminal/Cursor.mpp index 7a05fc49..235f0212 100644 --- a/modules/Terminal/Cursor.mpp +++ b/modules/Terminal/Cursor.mpp @@ -18,8 +18,8 @@ export namespace CppUtils::Terminal auto consoleScreenBufferInfo = CONSOLE_SCREEN_BUFFER_INFO{}; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleScreenBufferInfo); return Container::Size2{ - consoleScreenBufferInfo.srWindow.X, - consoleScreenBufferInfo.srWindow.Y}; + consoleScreenBufferInfo.srWindow.Left, + consoleScreenBufferInfo.srWindow.Top}; } #elif defined(OS_MAC) or defined(OS_LINUX) [[nodiscard]] inline auto getCursorPosition() -> std::expected @@ -41,7 +41,7 @@ export namespace CppUtils::Terminal #if defined(OS_WINDOWS) inline auto setCursorPosition(Container::Size2 position) -> void { - SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), COORD{position.x(), position.y()}); + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), COORD{static_cast(position.x()), static_cast(position.y())}); } #elif defined(OS_MAC) or defined(OS_LINUX) inline auto setCursorPosition([[maybe_unused]] Container::Size2 position) -> void diff --git a/modules/Terminal/Handle.mpp b/modules/Terminal/Handle.mpp index 90f03c4b..2e44eaf2 100644 --- a/modules/Terminal/Handle.mpp +++ b/modules/Terminal/Handle.mpp @@ -2,6 +2,8 @@ module; #include +#include + export module CppUtils.Terminal.Handle; import std; diff --git a/modules/Terminal/TextModifier.mpp b/modules/Terminal/TextModifier.mpp index d33b4232..d4845549 100644 --- a/modules/Terminal/TextModifier.mpp +++ b/modules/Terminal/TextModifier.mpp @@ -9,6 +9,7 @@ import CppUtils.Terminal.BackgroundColor; import CppUtils.Terminal.Utility; import CppUtils.Terminal.TextColor; import CppUtils.Terminal.TextStyle; +import CppUtils.Terminal.Handle; export namespace CppUtils::Terminal { diff --git a/tests/Container/DependencyGraph.mpp b/tests/Container/DependencyGraph.mpp index c3cd3191..a9a3ed45 100644 --- a/tests/Container/DependencyGraph.mpp +++ b/tests/Container/DependencyGraph.mpp @@ -141,7 +141,7 @@ export namespace CppUtils::UnitTest::Container::DependencyGraph suite.expect(not graph.hasCycle()); - graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void { + auto _ = graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void { std::println("{}: {}", key, value); }); }); @@ -159,7 +159,7 @@ export namespace CppUtils::UnitTest::Container::DependencyGraph suite.expect(graph.hasCycle()); - graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void { + auto _ = graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void { std::println("{}: {}", key, value); }); }); diff --git a/tests/Container/Stack.mpp b/tests/Container/Stack.mpp index 00596a72..cd819a10 100644 --- a/tests/Container/Stack.mpp +++ b/tests/Container/Stack.mpp @@ -82,7 +82,7 @@ export namespace CppUtils::UnitTest::Container::Stack auto getNumber = []() -> std::size_t { return 42uz; }; - stack.call(+getNumber); + auto _ = stack.call(+getNumber); { auto result = stack.pop(); suite.expect(result.has_value()); @@ -97,7 +97,7 @@ export namespace CppUtils::UnitTest::Container::Stack std::println("{}", nb); }; stack.push(42uz); - stack.call(print); + auto _ = stack.call(print); }); suite.addTest("Call function: (std::size_t, std::size_t) -> std::size_t", [&] { @@ -108,8 +108,8 @@ export namespace CppUtils::UnitTest::Container::Stack auto add = [](std::size_t lhs, std::size_t rhs) -> std::size_t { return lhs + rhs; }; - stack.call(add); - stack.drop(sizeof(std::size_t) * 2); + auto _ = stack.call(add); + auto _ = stack.drop(sizeof(std::size_t) * 2); { auto result = stack.pop(); suite.expect(result.has_value()); @@ -129,15 +129,15 @@ export namespace CppUtils::UnitTest::Container::Stack auto print = [](std::size_t nb) -> void { std::println("{}", nb); }; - stack.call(add); - stack.drop(sizeof(std::size_t) * 2); + auto _ = stack.call(add); + auto _ = stack.drop(sizeof(std::size_t) * 2); { auto result = stack.get(); suite.expect(result.has_value()); suite.expectEqual(result.value(), 42uz); } - stack.call(print); - stack.drop(sizeof(std::size_t)); + auto _ = stack.call(print); + auto _ = stack.drop(sizeof(std::size_t)); suite.expect(std::empty(stack)); }); }}; diff --git a/tests/FileSystem/Watcher.mpp b/tests/FileSystem/Watcher.mpp index 0583cce8..21e98867 100644 --- a/tests/FileSystem/Watcher.mpp +++ b/tests/FileSystem/Watcher.mpp @@ -1,3 +1,7 @@ +module; + +#include + export module CppUtils.UnitTests.FileSystem.Watcher; import std; @@ -10,18 +14,25 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher {"Logger", "FileSystem/Directory", "FileSystem/File"}, [](auto& suite) { using namespace std::chrono_literals; +#if defined(OS_LINUX) using Logger = CppUtils::Logger<"CppUtils">; +#endif suite.addTest("No file", [&] { CppUtils::FileSystem::TemporaryDirectory{[&suite](const auto& directory) -> void { auto watcher = CppUtils::FileSystem::Watcher{}; watcher.watch(directory / "test.tmp"); +#if defined(OS_LINUX) watcher.onEvent( [&suite]( [[maybe_unused]] CppUtils::FileSystem::Event event, [[maybe_unused]] const std::filesystem::path& filePath) -> void { suite.expect(false); }); +#else + auto &_ = suite; +#warning "TODO onEvent not implemented for this platform" +#endif std::this_thread::sleep_for(10ms); }}; }); @@ -33,12 +44,17 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher auto watcher = CppUtils::FileSystem::Watcher{}; watcher.watch(filePath); +#if defined(OS_LINUX) watcher.onEvent( [&suite]( [[maybe_unused]] CppUtils::FileSystem::Event event, [[maybe_unused]] const std::filesystem::path& filePath) -> void { suite.expect(false); }); +#else + auto &_ = suite; +#warning "TODO onEvent not implemented for this platform" +#endif std::this_thread::sleep_for(10ms); }}; }); @@ -59,6 +75,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher auto watcher = CppUtils::FileSystem::Watcher{}; watcher.watch(directory); +#if defined(OS_LINUX) watcher.onEvent( [](CppUtils::FileSystem::Event event, const std::filesystem::path& filePath) -> void { @@ -80,6 +97,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher suite.expectEqual(eventFilePath, filePath); expectCloseFile = true; }); +#else +#warning "TODO onEvent not implemented for this platform" +#endif CppUtils::FileSystem::String::write(directory / "test.tmp", "Hello World!"); std::this_thread::sleep_for(100ms); @@ -96,6 +116,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher auto watcher = CppUtils::FileSystem::Watcher{}; watcher.watch(filePath); +#if defined(OS_LINUX) watcher.onEvent( [](CppUtils::FileSystem::Event event, const std::filesystem::path& filePath) -> void { @@ -109,6 +130,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher suite.expectEqual(eventFilePath, filePath); expectModifyFile = true; }); +#else +#warning "TODO onEvent not implemented for this platform" +#endif CppUtils::FileSystem::String::write(filePath, "Bar"); std::this_thread::sleep_for(100ms); @@ -124,6 +148,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher auto watcher = CppUtils::FileSystem::Watcher{}; watcher.watch(directory); +#if defined(OS_LINUX) watcher.onEvent( [](CppUtils::FileSystem::Event event, const std::filesystem::path& filePath) -> void { @@ -137,6 +162,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher suite.expectEqual(eventFilePath, filePath); expectModifyFile = true; }); +#else +#warning "TODO onEvent not implemented for this platform" +#endif CppUtils::FileSystem::String::write(filePath, "Bar"); std::this_thread::sleep_for(100ms); @@ -152,6 +180,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher auto watcher = CppUtils::FileSystem::Watcher{}; watcher.watch(directory); +#if defined(OS_LINUX) watcher.onEvent( [](CppUtils::FileSystem::Event event, const std::filesystem::path& filePath) -> void { @@ -165,6 +194,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher suite.expectEqual(eventFilePath, filePath); expectDeleteFile = true; }); +#else +#warning "TODO onEvent not implemented for this platform" +#endif std::filesystem::remove(filePath); std::this_thread::sleep_for(100ms); diff --git a/tests/Type/Tuple.mpp b/tests/Type/Tuple.mpp index c6a39e7b..32ab03e4 100644 --- a/tests/Type/Tuple.mpp +++ b/tests/Type/Tuple.mpp @@ -16,7 +16,7 @@ export namespace CppUtils::UnitTest::Type::Tuple }; auto tuple = std::make_tuple(1, "Hello World!"); - CppUtils::Type::Tuple::visitAt(tuple, 1, function); + auto _ = CppUtils::Type::Tuple::visitAt(tuple, 1, function); suite.expect(called); }); diff --git a/xmake.lua b/xmake.lua index 34294b86..e9f49f53 100644 --- a/xmake.lua +++ b/xmake.lua @@ -3,7 +3,7 @@ set_version("0.0.0", {build = "%Y%m%d%H%M"}) set_license("LGPL3") set_languages("clatest", "cxxlatest") set_warnings("allextra", "pedantic", "error") -add_cxflags("clang::-Wconversion", "clang::-Wfatal-errors", "clang::-Wno-deprecated-declarations -Wno-unknown-attributes") +add_cxflags("clang::-Wno-error=#warnings", "clang::-Wconversion", "clang::-Wfatal-errors", "clang::-Wno-deprecated-declarations -Wno-unknown-attributes") add_cxflags("clang::-fcolor-diagnostics", "clang::-fansi-escape-codes", "gcc::-fdiagnostics-color=always") -- add_cxflags("-Wno-gnu-statement-expression-from-macro-expansion -Wno-gnu-statement-expression", {tools = { "clang", "gcc" }) set_optimize("fastest")