-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added type_id()
& type_size()
methods to the cetl::unbounded_variant
. #verification #docs #sonar
#127
Conversation
…ion #docs #sonar
…iant`. #verification #docs #sonar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the special case is removed it should be good to go
include/cetl/unbounded_variant.hpp
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_converters
context. make_converters
is 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - see commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…hould be explicitly specified.
…into sshirokov/type_id
Quality Gate failedFailed conditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks.
No description provided.