mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 08:46:53 +08:00
test_module: Fix noexcept warning
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<std::allocator<void> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = Type2; _Args = {Type2}; allocator_type = std::allocator<void>]’
.../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<void>; __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<void>; _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<void>; _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<void>; _Args = {Type2}; _Tp = Type2]’
.../include/c++/13.3.0/bits/shared_ptr.h:1009:14: required from ‘std::shared_ptr<std::_NonArray<_Tp> > 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; <template-parameter-1-2> = 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()::<lambda(const TestBaseType&)>; Type_Conversion = std::shared_ptr<detail::Type_Conversion_Base>]’
.../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.
This commit is contained in:
parent
681104b68f
commit
43dc35c3df
@ -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") {
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user