MISRA Discussion Forums

Full Version: What is the intention of A15-4-4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi experts,


Quote:Rule A15-4-4 (required, implementation, automated)

A declaration of non-throwing function shall contain noexcept specification.

provides this example (17-10):
// ...
void F1(); // Compliant - f1, without noexcept specification, declares to throw
// exceptions implicitly

// ...

The implementation of F1 is not provided.

I would assume that a matching implementation of  F1() would be, e.g. 
void F1() {
  // something ...
  throw std::runtime_error{"problem"};

My questions:
1. Is my implementation of F1 above correct?
2. What should a compliant static analysis tool report, when F1 does not throw?
3. Shall a compliant AUTOSAR C++ checker tool here report a violation (error/warning/...) or is this kind of a hint or note? 
4. What shall be reported for the operator()() of a lambda that does not throw and does not explicitly add noexcept (example: auto l = [font=Consolas, "Liberation Mono", Courier, monospace, Consolas, "Courier New", monospace][]() { return 42; }[/font])?
5. (Bonus question) will a similar check be added to the next version of MISRA C++?
1: It would be a valid implementation that makes F1 compliant
2: If a function cannot throw but is not marked as noexcept, it should be reported as a violation
3: Autosar does not define how a tool should report a violation
4: Lambdas are treated the same as other functions, so the example should be marked noexcept
5: Its under discussion, but currently we have no plans to include a similar rule