Added type_id() & type_size() methods to the cetl::unbounded_variant. #verification #docs #sonar - #127
Conversation
…ion #docs #sonar
…iant`. #verification #docs #sonar
pavel-kirienko
left a comment
There was a problem hiding this comment.
After the special case is removed it should be good to go
| value_const_converter_ = [](const void* const storage, const type_id& id) { | ||
| const auto ptr = static_cast<const Tp*>(storage); | ||
| return ptr->_cast_(id); | ||
| value_const_converter_ = [](const void* const storage, const cetl::type_id& dst_type_id) { |
There was a problem hiding this comment.
These lambdas may fail on systems with no heap and a deficient small-value-optimization in std::function. Please use function pointers to avoid this.
There was a problem hiding this comment.
I don't think so, they are just pure (implicitly generated) static functions, they don't capture anything (neither any of outside vars nor this), only Tp type information - so no allocation. sizeof of them is 1 (should kinda be zero but as you know even empty struct sizeof is 1). And the fact that I can just assign them to a simple pointer to function (see value_const_converter_ declaration below) proves it - as soon as add anything to the capture list such assignments won't compile anymore.
Here is sizeof of this lambda:
using Xxx = decltype([](const void* const storage, const cetl::type_id& dst_type_id) {
CETL_DEBUG_ASSERT(nullptr != storage, "");
const auto ptr = static_cast<const Tp*>(storage);
const void* const dst_ptr = ptr->_cast_(dst_type_id);
return std::make_pair(dst_ptr, cetl::type_id_value<Tp>);
});
static_assert(sizeof(Xxx) == 1);
There was a problem hiding this comment.
In addition, although I could technically make explicit template static member functions for convertors, I'm reluctant todo so b/c:
- There will be 4 of them (see two mutually exclusive versions of
make_converters). - They all will be out of
make_converterscontext. make_convertersis the only supposed entity to reference them; and of course nobody is allowed to call them directly (only indirectly viavalue_[mut|const]_convertor_function pointers). So, in some sense I believe am doing proper isolation here without introducing any indeterministic behavior (including memory allocations).- We also have other function pointer members initialized with lambdas in a similar manner (and isolation!), like
value_destroyer_,value_copier_andvalue_mover_. - Debugging is not affected - breakpoints or stepping into such lambdas perfectly works.
There was a problem hiding this comment.
Furthermore, I scanned AUTOSAR14 spec, and found no lambda rule against my implementation. The only remotely applicable rule is the following:
Rule A5-1-6 (advisory, implementation, automated)
Return type of a non-void return type lambda expression should be
explicitly specified.
I can fix it.
…hould be explicitly specified.
…into sshirokov/type_id
|



No description provided.