AutosarC++18_10-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
Required inputs: IR
std::terminate() to be called unexpectedly if a noexcept-declared
function throws.
Bad code (inconsistent noexcept across units):
// file1.h
void Process(); // No exception specification
// file1.cpp
void Process() noexcept { // ERROR: adds noexcept in definition
// ...
}
// file2.cpp
void Call() {
Process(); // Might throw, based on declaration
}
Bad code (override with different noexcept):
class Base {
public:
virtual void Handle() noexcept {
// Callers assume this won't throw
}
};
class Derived : public Base {
public:
void Handle() override { // ERROR: removed noexcept
// Now this can throw, violating base class contract
}
};
Good code (consistent noexcept):
// file1.h
void Process() noexcept;
// file1.cpp
void Process() noexcept { // OK: consistent
// ...
}
// file2.cpp
void Call() {
Process(); // Consistent: known that won't throw
}
Good code (override with consistent or more restrictive noexcept):
class Base {
public:
virtual void Handle() noexcept {
// Won't throw
}
};
class Derived : public Base {
public:
void Handle() noexcept override { // OK: same noexcept
// Implementation
}
};
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
noexcept_mismatch_redecl |
Function’s noexcept specification shall be identical |
None |
False |
noexpect_mismatch_override |
exception specification for virtual function “{}” is incompatible with that of overridden function “{}” |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.