From 891d6fd0bab2e819f599d08ce299eee5cd0db154 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 20 Apr 2025 13:31:19 +0200 Subject: [PATCH 1/4] Fix warning: -Wmaybe-uninitialized In member function 'ESM::RefId {anonymous}::IdGettingVisitor::operator()(const MWWorld::Ptr&) const', inlined from 'constexpr _Res std::__invoke_impl(__invoke_other, _Fn&&, _Args&& ...) [with _Res = ESM::RefId; _Fn = {anonymous}::IdGettingVisitor; _Args = {const MWWorld::Ptr&}]' at /usr/include/c++/13/bits/invoke.h:61:36, inlined from 'constexpr typename std::__invoke_result<_Functor, _ArgTypes>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = {anonymous}::IdGettingVisitor; _Args = {const MWWorld::Ptr&}]' at /usr/include/c++/13/bits/invoke.h:96:40, inlined from 'static constexpr decltype(auto) std::__detail::__variant::__gen_vtable_impl, std::integer_sequence >::__visit_invoke(_Visitor&&, _Variants ...) [with _Result_type = std::__detail::__variant::__deduce_visit_result; _Visitor = {anonymous}::IdGettingVisitor&&; _Variants = {const std::variant >&}; long unsigned int ...__indices = {0}]' at /usr/include/c++/13/variant:1060:24, inlined from 'constexpr decltype(auto) std::__do_visit(_Visitor&&, _Variants&& ...) [with _Result_type = __detail::__variant::__deduce_visit_result; _Visitor = {anonymous}::IdGettingVisitor; _Variants = {const variant >&}]' at /usr/include/c++/13/variant:1815:5, inlined from 'constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = {anonymous}::IdGettingVisitor; _Variants = {const variant >&}]' at /usr/include/c++/13/variant:1878:34, inlined from 'ESM::RefId MWScript::GlobalScriptDesc::getId() const' at ../../../apps/openmw/mwscript/globalscripts.cpp:120:26: ../../../apps/openmw/mwscript/globalscripts.cpp:91:35: error: '*(const uint32_t*)((char*)& + offsetof(ESM::RefId, ESM::RefId::mValue.std::variant::.std::__detail::__variant::_Variant_base::.std::__detail::__variant::_Move_assign_base::.std::__detail::__variant::_Copy_assign_base::.std::__detail::__variant::_Move_ctor_base::.std::__detail::__variant::_Copy_ctor_base::.std::__detail::__variant::_Variant_storage::_M_u))' may be used uninitialized [-Werror=maybe-uninitialized] 91 | return ESM::RefId(); | ^ ../../../apps/openmw/mwscript/globalscripts.cpp: In member function 'ESM::RefId MWScript::GlobalScriptDesc::getId() const': ../../../apps/openmw/mwscript/globalscripts.cpp:91:35: note: '' declared here 91 | return ESM::RefId(); | ^ --- components/esm/refid.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp index 174652419a..919ff59223 100644 --- a/components/esm/refid.hpp +++ b/components/esm/refid.hpp @@ -70,7 +70,10 @@ namespace ESM static RefId esm3ExteriorCell(int32_t x, int32_t y) { return RefId(ESM3ExteriorCellRefId(x, y)); } - constexpr RefId() = default; + constexpr RefId() noexcept + : mValue(EmptyRefId{}) + { + } constexpr RefId(EmptyRefId value) noexcept : mValue(value) From 875a45837a50eed514bc6933b91e22dd60c13f61 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 25 Apr 2025 20:02:57 +0200 Subject: [PATCH 2/4] Disable -Warray-bounds due to GCC bug To avoid getting warnings like: In file included from ../../../extern/sol3/sol/compatibility.hpp:46, from ../../../extern/sol3/sol/bytecode.hpp:27, from ../../../extern/sol3/sol/sol.hpp:51, from ../../../components/lua/luastate.hpp:8, from ../../../apps/openmw/mwlua/context.hpp:4, from ../../../apps/openmw/mwlua/soundbindings.hpp:6, from ../../../apps/openmw/mwlua/soundbindings.cpp:1: In member function 'void sol::stack::field_getter >::get(lua_State*, Key&&, int) [with Key = const char (&)[7]; T = char [7]; bool global = false; bool raw = false; = void]', inlined from 'void sol::stack::get_field(lua_State*, Key&&, int) [with bool global = false; bool raw = false; Key = const char (&)[7]]' at ../../../extern/sol3/sol/stack_core.hpp:1210:62, inlined from 'sol::stack::probe sol::stack::probe_field_getter >::get(lua_State*, Key&&, int) [with Key = const char (&)[7]; T = char [7]; P = float; bool b = false; bool raw = false; = void]' at ../../../extern/sol3/sol/stack_probe.hpp:41:21, inlined from 'sol::stack::probe sol::stack::probe_field_getter >::get(lua_State*, Key&&, int) [with Key = const char (&)[6]; T = char [6]; P = float; bool b = false; bool raw = false; = void]' at ../../../extern/sol3/sol/stack_probe.hpp:35:9, inlined from 'sol::stack::probe sol::stack::probe_get_field(lua_State*, Key&&, int) [with bool global = false; bool raw = false; C = float; Key = const char (&)[6]]' at ../../../extern/sol3/sol/stack_core.hpp:1230:78, inlined from 'decltype(auto) sol::basic_table_core<, >::traverse_get_deep_optional(int&, int, Key&&, Keys&& ...) const [with bool global = false; bool raw = false; sol::detail::insert_mode mode = sol::detail::none; T = sol::optional; Key = const char (&)[6]; Keys = {}; bool top_level = false; ref_t = sol::basic_reference]' at ../../../extern/sol3/sol/table_core.hpp:217:62, inlined from 'decltype(auto) sol::basic_table_core<, >::traverse_get_single(int, Keys&& ...) const [with bool raw = false; Ret = sol::optional; Keys = {const char (&)[6]}; bool top_level = false; ref_t = sol::basic_reference]' at ../../../extern/sol3/sol/table_core.hpp:123:83, inlined from 'decltype(auto) sol::basic_table_core<, >::traverse_get_single_maybe_tuple(int, Key&&) const [with bool raw = false; Ret = sol::optional; Key = const char (&)[6]; bool top_level = false; ref_t = sol::basic_reference]' at ../../../extern/sol3/sol/table_core.hpp:113:41, inlined from 'decltype(auto) sol::basic_table_core<, >::tuple_get(int, Keys&& ...) const [with bool raw = false; Ret = {sol::optional}; Keys = {const char (&)[6]}; bool top_level = false; ref_t = sol::basic_reference]' at ../../../extern/sol3/sol/table_core.hpp:93:56, inlined from 'decltype(auto) sol::basic_table_core<, >::get(Keys&& ...) const [with Ret = {sol::optional}; Keys = {const char (&)[6]}; bool top_level = false; ref_t = sol::basic_reference]' at ../../../extern/sol3/sol/table_core.hpp:422:35, inlined from 'decltype(auto) sol::basic_table_core<, >::get_or(Key&&, T&&) const [with T = float; Key = const char (&)[6]; bool top_level = false; ref_t = sol::basic_reference]' at ../../../extern/sol3/sol/table_core.hpp:428:41, inlined from '{anonymous}::PlaySoundArgs {anonymous}::getPlaySoundArgs(const sol::optional > >&)' at ../../../apps/openmw/mwlua/soundbindings.cpp:62:42: ../../../extern/sol3/sol/stack_field.hpp:116:49: error: array subscript 'const char [7][0]' is partly outside array bounds of 'const char [6]' [-Werror=array-bounds=] 116 | lua_getfield(L, tableindex, &key[0]); | ^~~~~~~~~~~~ See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438. Simplified example: https://godbolt.org/z/ccPje4nK1. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94b52e0156..bd66eb2c48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -594,6 +594,11 @@ endif() if (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) set(OPENMW_CXX_FLAGS "-Wall -Wextra -Wundef -Wextra-semi -Wno-unused-parameter -pedantic -Wno-long-long -Wnon-virtual-dtor -Wunused ${OPENMW_CXX_FLAGS}") + if (CMAKE_CXX_COMPILER_ID STREQUAL GNU) + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438 + set(OPENMW_CXX_FLAGS "-Wno-array-bounds ${OPENMW_CXX_FLAGS}") + endif() + if (APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") From a5826b75e0635dc340fb549353534827ad977911 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 25 Apr 2025 20:14:28 +0200 Subject: [PATCH 3/4] Disable -Werror for ASAN builds To avoid warnings like: In file included from /usr/include/c++/13/regex:50, from ../../components/lua/yamlloader.cpp:6: In constructor 'std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes ...)>&&) [with _Res = bool; _ArgTypes = {char}]', inlined from 'std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type>&&) [with _Char_type = char]' at /usr/include/c++/13/bits/regex_automaton.h:149:4, inlined from 'std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_begin() [with _TraitsT = std::__cxx11::regex_traits]' at /usr/include/c++/13/bits/regex_automaton.h:281:24: /usr/include/c++/13/bits/std_function.h:405:42: error: '*(std::function*)((char*)&__tmp + offsetof(std::__detail::_StateT, std::__detail::_State::.std::__detail::_State_base::)).std::function::_M_invoker' may be used uninitialized [-Werror=maybe-uninitialized] 405 | : _Function_base(), _M_invoker(__x._M_invoker) | ~~~~^~~~~~~~~~ In file included from /usr/include/c++/13/regex:65: /usr/include/c++/13/bits/regex_automaton.h: In member function 'std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_begin() [with _TraitsT = std::__cxx11::regex_traits]': /usr/include/c++/13/bits/regex_automaton.h:279:17: note: '__tmp' declared here 279 | _StateT __tmp(_S_opcode_subexpr_begin); | ^~~~~ See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562. --- .gitlab-ci.yml | 5 +++++ CI/before_script.linux.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ad17f34af7..000b19c68b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,6 +56,7 @@ Ubuntu_GCC_preprocess: stage: build variables: CMAKE_EXE_LINKER_FLAGS: -fuse-ld=mold + OPENMW_CXX_FLAGS: "-Werror -Werror=implicit-fallthrough" script: - df -h - export CCACHE_BASEDIR="`pwd`" @@ -156,6 +157,8 @@ Ubuntu_GCC_asan: CMAKE_CXX_FLAGS_DEBUG: -g -O1 -fno-omit-frame-pointer -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak CMAKE_EXE_LINKER_FLAGS: -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak -fuse-ld=mold BUILD_OPENMW_ONLY: 1 + # Disable -Werror due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562 + OPENMW_CXX_FLAGS: "" Clang_Format: extends: .Ubuntu_Image @@ -257,6 +260,8 @@ Ubuntu_GCC_tests_asan: CMAKE_CXX_FLAGS_DEBUG: -g -O1 -fno-omit-frame-pointer -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak CMAKE_EXE_LINKER_FLAGS: -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak -fuse-ld=mold ASAN_OPTIONS: halt_on_error=1:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 + # Disable -Werror due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562 + OPENMW_CXX_FLAGS: "" artifacts: paths: [] name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA} diff --git a/CI/before_script.linux.sh b/CI/before_script.linux.sh index c6fd306e25..c5704b900c 100755 --- a/CI/before_script.linux.sh +++ b/CI/before_script.linux.sh @@ -17,7 +17,7 @@ declare -a CMAKE_CONF_OPTS=( -DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS:-OFF}" -DUSE_SYSTEM_TINYXML=ON -DOPENMW_USE_SYSTEM_RECASTNAVIGATION=ON - -DOPENMW_CXX_FLAGS="-Werror -Werror=implicit-fallthrough" # flags specific to OpenMW project + -DOPENMW_CXX_FLAGS="${OPENMW_CXX_FLAGS}" # flags specific to OpenMW project ) if [[ "${CMAKE_EXE_LINKER_FLAGS}" ]]; then From b5f8a0ecdb25d67e8ae807861c69f7e4b54ffa84 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 26 Apr 2025 00:02:05 +0200 Subject: [PATCH 4/4] Fix warning: -Wstring-compare In file included from ../../../components/esm/defs.hpp:7, from ../../../apps/components_tests/esm/test_fixed_string.cpp:1: In function 'bool ESM::operator==(const FixedString&, const char (&)[rhsSize]) [with long unsigned int capacity = 4; long unsigned int rhsSize = 12]', inlined from 'virtual void {anonymous}::EsmFixedString_empty_strings_Test::TestBody()' at ../../../apps/components_tests/esm/test_fixed_string.cpp:82:13: ../../../components/esm/esmcommon.hpp:142:85: error: 'int strncmp(const char*, const char*, size_t)' of strings of length 0 and 4 and bound of 4 evaluates to nonzero [-Werror=string-compare] 142 | return strnlen(rhs, rhsSize) == strnlen(lhs.mData, capacity) && std::strncmp(lhs.mData, rhs, capacity) == 0; | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ --- apps/components_tests/esm/test_fixed_string.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/components_tests/esm/test_fixed_string.cpp b/apps/components_tests/esm/test_fixed_string.cpp index 76ed346daa..2241bb042f 100644 --- a/apps/components_tests/esm/test_fixed_string.cpp +++ b/apps/components_tests/esm/test_fixed_string.cpp @@ -74,19 +74,20 @@ namespace TEST(EsmFixedString, empty_strings) { + constexpr std::string_view someStr = "some string"; { SCOPED_TRACE("4 bytes"); ESM::NAME empty = ESM::NAME(); EXPECT_TRUE(empty == ""); EXPECT_TRUE(empty == static_cast(0)); - EXPECT_TRUE(empty != "some string"); + EXPECT_TRUE(empty != someStr); EXPECT_TRUE(empty != static_cast(42)); } { SCOPED_TRACE("32 bytes"); ESM::NAME32 empty = ESM::NAME32(); EXPECT_TRUE(empty == ""); - EXPECT_TRUE(empty != "some string"); + EXPECT_TRUE(empty != someStr); } }