rspec/rules/S1041/cfamily/rule.adoc
Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.
2023-06-22 10:38:01 +02:00

53 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
If a program throws an unhandled exception it terminates in an implementation-defined manner. In particular, it is implementation-defined whether the call stack is unwound before termination, so the destructors of any automatic objects may or may not be executed. By enforcing the provision of a “last-ditch catch-all”, the developer can ensure that the program terminates in a consistent manner.
The possible exceptions from a program should be caught as a matter of course. This rules objective is to ensure that exceptions that were _not_ expected are also caught.
=== Compliant solution
For the majority of programs this will mean ``++main++`` should look like:
[source,cpp]
----
int32_t main( )
{
try
{
// program code
}
catch ( ... ) // Catch-all handler
{
// Handle unexpected exceptions
}
return 0;
}
----
== Resources
* MISRA {cpp}:2008, 15-3-2
* https://cwe.mitre.org/data/definitions/391[MITRE, CWE-391] - Unchecked Error Condition
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add a "catch ( ... )" handler to catch the possibly thrown exceptions.
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]