From 43dc35c3dfb82dd95b55300270c102ad45e8fbce Mon Sep 17 00:00:00 2001 From: Clemens Terasa Date: Wed, 19 Feb 2025 19:33:28 +0100 Subject: [PATCH] test_module: Fix noexcept warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With gcc 13.3.0 an `-Wnoexcept` I warnings like the following: ``` In file included from .../include/c++/13.3.0/bits/char_traits.h:57, from .../include/c++/13.3.0/string_view:40, from .../ChaiScript/include/chaiscript/chaiscript_defines.hpp:23, from .../ChaiScript/include/chaiscript/chaiscript_basic.hpp:10, from .../ChaiScript/src/test_module.cpp:2: .../include/c++/13.3.0/bits/stl_construct.h: In instantiation of ‘constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = Type2; _Args = {Type2}; decltype (::new(void*(0)) _Tp) = Type2*]’: .../include/c++/13.3.0/bits/stl_construct.h:115:21: required from ‘constexpr void std::_Construct(_Tp*, _Args&& ...) [with _Tp = Type2; _Args = {Type2}]’ .../include/c++/13.3.0/bits/alloc_traits.h:661:19: required from ‘static constexpr void std::allocator_traits >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = Type2; _Args = {Type2}; allocator_type = std::allocator]’ .../include/c++/13.3.0/bits/shared_ptr_base.h:604:39: required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {Type2}; _Tp = Type2; _Alloc = std::allocator; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ .../include/c++/13.3.0/bits/shared_ptr_base.h:971:16: required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = Type2; _Alloc = std::allocator; _Args = {Type2}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ .../include/c++/13.3.0/bits/shared_ptr_base.h:1712:14: required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator; _Args = {Type2}; _Tp = Type2; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ .../include/c++/13.3.0/bits/shared_ptr.h:464:59: required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator; _Args = {Type2}; _Tp = Type2]’ .../include/c++/13.3.0/bits/shared_ptr.h:1009:14: required from ‘std::shared_ptr > std::make_shared(_Args&& ...) [with _Tp = Type2; _Args = {Type2}; _NonArray<_Tp> = Type2]’ .../ChaiScript/include/chaiscript/dispatchkit/boxed_value.hpp:121:37: required from ‘static auto chaiscript::Boxed_Value::Object_Data::get(T, bool) [with T = Type2]’ .../ChaiScript/include/chaiscript/dispatchkit/boxed_value.hpp:133:34: required from ‘chaiscript::Boxed_Value::Boxed_Value(T&&, bool) [with T = Type2; = void]’ .../ChaiScript/include/chaiscript/dispatchkit/type_conversions.hpp:480:26: required from ‘chaiscript::Type_Conversion chaiscript::type_conversion(const Callable&) [with From = TestBaseType; To = Type2; Callable = create_chaiscript_module_test_module()::; Type_Conversion = std::shared_ptr]’ .../ChaiScript/src/test_module.cpp:194:58: required from here .../include/c++/13.3.0/bits/stl_construct.h:95:14: warning: noexcept-expression evaluates to ‘false’ because of a call to ‘Type2::Type2(Type2&&)’ [-Wnoexcept] 95 | noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...))) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../ChaiScript/src/test_module.cpp:60:7: note: but ‘Type2::Type2(Type2&&)’ does not throw; perhaps it should be declared ‘noexcept’ 60 | class Type2 { | ^~~~~ ``` Fix this by introducing `noexcept` like proposed in the warning. --- src/test_module.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test_module.cpp b/src/test_module.cpp index 6568b9b2..5da2d389 100644 --- a/src/test_module.cpp +++ b/src/test_module.cpp @@ -5,30 +5,30 @@ class TestBaseType { public: - TestBaseType() + TestBaseType() noexcept : val(10) , const_val(15) , mdarray{} { } - TestBaseType(int) + TestBaseType(int) noexcept : val(10) , const_val(15) , mdarray{} { } - TestBaseType(int *) + TestBaseType(int *) noexcept : val(10) , const_val(15) , mdarray{} { } - TestBaseType(const TestBaseType &other) + TestBaseType(const TestBaseType &other) noexcept : val(other.val) , const_val(other.const_val) , const_val_ptr(&const_val) , func_member(other.func_member) { } - TestBaseType(TestBaseType &&other) + TestBaseType(TestBaseType &&other) noexcept : val(other.val) , const_val(other.const_val) , const_val_ptr(&const_val) @@ -59,7 +59,7 @@ public: class Type2 { public: - Type2(TestBaseType t_bt) + Type2(TestBaseType t_bt) noexcept : m_bt(std::move(t_bt)) , m_str("Hello World") { }