AUTOSAR C++14 Rule A15-4-3
The noexcept specification of a function shall either be identical across all translation units, or identical or more restrictive between a virtual member function and an overrider
Since R2020b
Description
Rule Definition
The noexcept specification of a function shall either be identical across all translation units, or identical or more restrictive between a virtual member function and an overrider.
Rationale
Translation units are the different source files that the compiler compiles. When a function has a different exception specification in different source files, it might result in undefined behavior. Similarly, a different exception specification of a polymorphic function in different levels of a class hierarchy might result in compilation failure in some cases. Depending on the software and hardware that you use, different exception specifications of a function in different places might cause a compilation failure or result in undefined behavior leading to security vulnerabilities.
To avoid undefined behavior and security vulnerabilities:
Keep the same exception specification in all declarations of a function.
If a virtual function is declared by using
noexcept
ornoexcept(true)
as the exception specification, declare the overrider functions in the derived classes by using the same specification.If a virtual function is declared by using
noexcept(false)
as the exception specification, declare the overrider functions in the derived classes by using eithernoexcept(false)
ornoexcept(true)
as the exception specification.
Polyspace Implementation
Polyspace® flags the exception specification of a function if the function is declared
with different exception specifications in different places in a file. Polyspace flags an overrider function in a derived class if it is specified as
noexcept(fale)
while the virtual function in the base class is
specified as noexcept
.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Exception handling |
Category: Required, Automated |
Version History
Introduced in R2020b