-
Notifications
You must be signed in to change notification settings - Fork 3k
Add C++11/14 support utility file #10868
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
Conversation
@kjbracey-arm, thank you for your changes. |
The majority of content in this file is a crutch to fill in the limited C++11 support in ARM C 5, so there is at least some chance of someone being able to build master with ARM C 5 once later PRs start using C++11/14. I could leave it out and greatly simplify it, but it would mean ARM C 5 builds will soon just not work at all. |
Last commit looks great! And maybe it would deserve its own PR. Few things that can be added:
|
I've actually dropped it from this PR for now, and agree that it would. I believe there are some glitches with backporting it to C++14 - in particular stricter enum initialization rules, so it might not quite fly. (I'm not 100% sold on
Good point.
Indeed, thanks for pointing that out! Just spotted that myself an hour ago. (Not by reading the documentation - by doing
Sorry, no. ARM C 5 does not support alignof/alignas.
Will look at those. |
BTW, ARM C 5 cannot do expression SFINAE, so the Span.h |
That's one more reason to implement |
Okay, added most of your suggestions. It seems there is enough to get all the alignment things apparently working, except I've baulked at |
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.
It's not really a functionality change, more of a "feature" in a sense we enable something new in the old compiler.
@pan- are you happy with the updates ? |
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.
Very good!
It would be nice to have some tests to static_assert
results of traits
and make sure compilation passes on all target; today that file isn't included anywhere and won't disrupt the CI even if there's error inside. I can help with that if you need a hand.
Note: I haven't reviewed array and what's bellow yet.
} // namespace impl | ||
|
||
template <typename T> | ||
struct is_member_pointer : impl::is_unqualified_member_pointer<remove_cv_t<T>> { }; |
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.
mbed::disjunction< is_member_function_pointer<T>, is_member_object_pointer<T>>
?
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.
Logically, that's what it is, and it's shorter to write, but I shuddered at the expanded complexity. Each of those is a very simple template specialization, leading to the very complex is_function
.
Seemed weird to effectively write if ((is_member && is_function) || (is_member && !is_function))
when is_function
is so complex and is_member
so simple.
But I have no good feel on how to optimise for compilation speed. I guess the disjunction
form less work when not instantiated, as it's a single template? But if instantiated it's dozens of times more complex.
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.
Created a new version passing a filter template to the is member detector. Not sure if that's better.
platform/mbed_cxxsupport.h
Outdated
|
||
/* forward */ | ||
template <typename T> | ||
T &&forward(remove_reference_t<T> &a) noexcept |
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.
Same as above, it may be marked as constexpr.
You should also provide the second overload:
template <typename T>
T &&forward(remove_reference_t<T> &&a) noexcept
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.
Hmm, lifted that from ARM C 5 manual, which only had the first overload. I wonder if there was any reason for that, or just an editorial error.
"feature" isn't on the list template :) |
Thanks for scanning though this. The CI isn't currently going to catch anything from the bulk of this anyway, as ARM C 5 is not tested. (!) Nevertheless, some tests would be appreciated. It would be worth you doing them as a second pair of eyes - it's always better if people don't write their own tests, and as this is implementing a clear external spec, we get to cross-check interpretation of that spec. Actual static asserts should be straightforward to pass - more problematic is SFINAE traits use in I'm somewhat torn on how much effort to expend on ARM C 5. We're liable to end up doing 90% of the work in this area for a non-supported toolchain... |
Thanks @kjbracey-arm I will add tests for the traits you added then. On one of the project I'm working on; we're working with ARM C 5 and C++11 enabled. I've already re-implemented some of the traits we needed but a more complete shim is more than welcome. It feels like a complete move to ARMC 5 was a bit premature as ARMC 6 hasn't caught up yet on density of the code it generates. Size really matters for customers. |
Updated incorporating comments. I feel bad adding 1000 lines of templates to a header (no doubt more for non ARM C 5 pulling in a real So I'm going to offset by taking 4000 lines out of Callback.h in another PR in a moment. |
The detection idiom is driving me slightly nuts. As far as I can see, Then any idiom I construct manually with
Or a But trying to do the same test via the detection idiom, eg |
Added |
As we start trying to use new facilities, we're likely to need some more helpers. In particular, ARM C 5 has no C++11 support in its library at all, so to avoid totally breaking it we need some backup. For the other toolchains, we can add a few C++17/C++20/TS extensions into namespace mbed to make life a little easier. * For ARM C 5: C++14 type_traits subset, std::move, std::forward, std::array, std::initializer_list, std::begin, std::end, std::align, std::maxalign_t, std::aligned_storage, alignof + alignas macro replacements. * For ARM C 5: MBED_CONSTEXPR_FN_14 and MBED_CONSTEXPR_OBJ_14 to mark things that can only be constexpr in C++14 or later. * For other compilers: mbed::void_t, mbed::type_identity, mbed::conjunction, mbed::disjunction, mbed::negation, mbed::experimental::nonesuch, mbed::experimental::is_detected family, mbed::remove_cvref, mbed::as_const.
Couple more minor tweaks - simplify "add_pointer"/"add_reference", then add "referenceable" checks. Flag out the detector idiom until we can figure out how to make it work on ARM C 5. |
Hopefully ARMC6 gets there asap 🙏 @pan- Happy with this as it is now? |
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.
👍 makes my head to spin hard :-)))))
CI started |
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.
LGTM.
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
As we start trying to use new facilities, we're likely to need some more helpers.
In particular, ARM C 5 has no C++11 support in its library at all, so to avoid totally breaking it we need some backup.
For the other toolchains, we can add a few C++17/C++20/TS extensions into
namespace mbed
to make life a little easier.type_traits
subset,std::move
,std::forward
,std::array
,std::initializer_list
,std::begin
,std::end
,std::align
,std::maxalign_t
,std::aligned_storage
,alignof
+alignas
macro replacements.MBED_CONSTEXPR_FN_14
andMBED_CONSTEXPR_OBJ_14
to mark things that can only beconstexpr
in C++14 or later.mbed::void_t
,mbed::type_identity
,mbed::conjunction
,mbed::disjunction
,mbed::negation
,mbed::experimental::nonesuch
,mbed::experimental::is_detected
family,mbed::as_const
,mbed::remove_cvref
.Pull request type
Reviewers
@pan-, @bulislaw
Release Notes
mbed_cxxsupport.h
to assist with C++11 and later code, including supporting ARM C 5 as much as possible.