Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing C++17 in safety critical systems

I'm currently thinking about C++ in safety-critical software (DO-178C DAL-D) and definitions of a coding standard. I was looking at MISRA C++ which is again 10 years old and misses all the C++11…17 features.

While being conservative regarding safety is often not a bad idea, the new language features might be beneficial to safety.

During reviews one has to argue about why you made certain decisions. And one can always argue that the new language features make the code clearer …thus fewer errors regarding misunderstandings; especially if the compiler is able to test and verify your assumptions.

But it is hard to find language features that carry the safety aspects more prominently than "make things clearer". What aspects of modern C++ really help regarding safety?

I'm setting up a small exercise project to test these ideas and currently totally focused on the "let the compiler check your assumptions". For example, we have just started to use [[nodiscard]] and found at least two bugs this way within the first hour. But what aspects of modern c++ were designed and shall be used with safety in mind?

like image 475
Hhut Avatar asked Jul 05 '18 06:07

Hhut


1 Answers

These come to my mind first :

  • atomic and memory_model : they allow writing portable code in concurrent / lockfree contexts.
  • unique_ptr : helps simplify memory handling
  • override lets you find bugs at compile time.
  • constexpr if makes the code be written closer to where it is used, which helps writing less bugs (sometimes, to specialize a behaviour according to a template parameter, you would write a class with n specializations. Now you can use if constexpr with n branches instead).

etc... in a way, considering the benefits on code clarity and portability, I think every feature of C++11/14/17 helps.

like image 82
Olivier Sohn Avatar answered Oct 16 '22 18:10

Olivier Sohn