ARMmbed / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
4.66k stars 2.97k forks source link

Align C++ version with compiler supported. #5507

Closed pan- closed 5 years ago

pan- commented 6 years ago

Description


Enhancement

Reason to enhance or problem with existing solution

Mbed OS 5.8 will be a leap forward in compiler supports. ARM compiler v5.06 will be deprecated in favor of v6.7and IAR v7.8 will be deprecated in favor of IAR v8.2. For both of these compilers the major version change induce a change in the version of C++ they support:

mbed os 5.6

C++98 C++11 C++14
GCC 6 X X X
ARM 5.06 X ~ partial -
IAR 7.80 X - -

mbed-os 5.8

C++98 C++11 C++14
GCC 6 X X X
ARMC 6.7 X X beta
IAR 8.2 - - X

The choice of C++98 as the C++ standard supported by mbed was obvious for mbed OS 5.6 but it is not for mbed OS 5.8 because IAR v8.2 only compile in C++ 14 mode and does not provide backward compatibility mode.

As close as they are C++98, C++11 and C++14 standards are not 100% backward compatible. As a consequence an mbed os 5.8 application may compile on one compiler and not the other or act slightly differently. The introduction of new keywords may also breaks existing applications.

Suggested enhancement

There is no lowest common denominator between the compiler that mbed OS 5.8 will support. However C++14 is much closer to C++11 than C++98. I'd suggest to define C++11 as the mode used by C++ compilers when they compile an mbed application and use C++14 when the ARM compiler supports it officially (in beta actually).

From my perspective it doesn't mean that our codebase should allow new features of the standards mentioned above. I believe this question should be addressed in a different thread; we can use the CI to ensure that our code base follows our actual guideline.

Notes:

Breaking changes introduced by C++11 can be found in the Section C2 of the C++11 specification and breaking changes introduced by C++14 can be found in the section C3 of the C++14 specification.

idea--list commented 5 years ago

@theotherjimmy Thanks!

embeddedteam103 commented 5 years ago

Now that the ARM compiler has official support for C++14, what is the status of this issue? I understand the callback changes are the most massive. Is it merely waiting a PR, or are there other outstanding issues?

kjbracey commented 5 years ago

Clearly we didn't hit the schedule stated in the original issue.

I believe we're currently aiming for compiler updates to ARMC6 and IAR8 in Mbed OS 5.12, and C++14/C11 mode for all toolchains in Mbed OS 5.13.

Changes to the codebase to use new language features, like that callback discussion would probably come later - it would be beneficial for 5.13 to "unofficially" allow users to select C++03/C99 to give ARMCC and GCC customers a bit of time to deal with compatibility issues in their own code.

I don't really want to have to fill the codebase with lots of if __cplusplus >= 2011xxxx to start conditionally using new features - I'd rather just hold off a little then go knowing we're relying on C++11.

embeddedteam103 commented 5 years ago

@kjbracey-arm This seems like a reasonable approach.

I don't really want to have to fill the codebase with lots of if __cplusplus >= 2011xxxx to start conditionally using new features - I'd rather just hold off a little then go knowing we're relying on C++11.

One thing to add: in C++17'sh standardized feature test macros, this is less of a problem (and maybe the supported toolchains will implement it before C++ 17 support?)

Advancement of the language is in my view completely parallel to advancement in the code itself (adding the new feature -> deprecating old one -> removing support for old one), the only difference is the time scale.

0xc0170 commented 5 years ago

@kjbracey-arm @pan- Is this issue still valid? There was an update to C++1x that resolves this one or there is still something missing?

kjbracey commented 5 years ago

I think this was closed by #10427

pan- commented 5 years ago

I'm closing!