Compiler still not using C++20 #308
Replies: 6 comments 5 replies
-
Your probably need to look into profiles settings mbed-os/tools/profiles/debug.json Lines 2 to 17 in 2deef5a However, the compiler will probably report many issues because MbedOS code base is compatible with older version i think. |
Beta Was this translation helpful? Give feedback.
-
I think more issues will popup if I do the switch. As long as the whole project is not C++20 compliant, users are not encouraged to switch to the latstest standard because of these potential issues. I don't know if there are 'programming rules' in the CE to align programming efforts into a specific C++ revision? |
Beta Was this translation helpful? Give feedback.
-
In Mbed-os, the C++ standard was long time only C++11 and also not always using the current gcc. It was handled conservative because changes caused a lot of testing to ensure the correct functions. And Mbed-os had to maintain compatibility for GCC, IAR and Keil compilers, and not all where always at the same standard level. Also the C++ runtime libs differ and new features are usually later available in Cortex-M than in X86/64 architectures. |
Beta Was this translation helpful? Give feedback.
-
Hmm... I am a bit hesitant to change all of Mbed to C++20, because the Arduino IDE is using a very old GCC version that does not support it, so it would break Arduino support. That said, you can enable C++20 for your own code, I believe, by doing something like
That will enable C++20 support for a specific executable target (MyExecutable). Let me know if that's not working! |
Beta Was this translation helpful? Give feedback.
-
I did not switched to C++20 because of all potential issues and warnings. I used the 'old way' practices. However this could be a discussion point for the whole community how and when to switch to a newer cpp version to make it feature proof. I don't know if there is already a topic created for it. I prefer using the 'out of the box' practices as much as possible. |
Beta Was this translation helpful? Give feedback.
-
I tried several methods.
To avoid a warning when passing a lambda:
Instead of (lower C++ versions):
But the C++ is using 20 because the auto warning is away.
Then -std=c++20 is added to CMAKE_CXX_FLAGS:STRING in CMakeCache.txt in the build folder but I still have the auto warning.
versus
or
So what should be the right way to enable c++20? |
Beta Was this translation helpful? Give feedback.
-
When you use typical C++20 features like:
typedef std::map<const char*, Widget*, decltype([](const char* str1, const char* str2){ return std::strcmp(str1, str2) < 0; }) > widget_level_map;
Then you get:
[build] /home/sam/git/hmipanel/source/widgets/widget.h:30:49: error: lambda-expression in unevaluated context only available with '-std=c++20' or '-std=gnu++20'
You have to do the 'old' way:
Another option is to use string objects instead of string literals, which compare the content of the string instead of the pointer address (which points to the same literal when used more than once in your code as a optimalization but does not allow dynamic update). However my feeling is that it works less efficiënt.
typedef std::map<std::string, Widget*> widget_level_map;
Beta Was this translation helpful? Give feedback.
All reactions