AutosarC++18_03-A15.4.3

Function’s noexcept specification shall be either identical or more restrictive across all translation units and all overriders

Required inputs: IR

When a function is redeclared or overridden across translation units, its noexcept specification must be consistent. If a base class virtual function has a noexcept specification, derived class overrides must have an identical or more restrictive specification. Overrides with an incompatible noexcept specification are ill-formed. Inconsistent declarations across translation units are an ODR violation: the compiler generates exception-handling code based on whichever declaration it sees, which can cause 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