Here I found that:
Inheriting constructors [...] are all noexcept(true) by default, unless they are required to call a function that is noexcept(false), in which case these functions are noexcept(false).
Does it mean that in the following example the inherited constructor is noexcept(true)
, even though it has been explicitly defined as noexcept(false)
in the base class, or it is considered for itself as a function that is noexcept(false) to be called?
struct Base {
Base() noexcept(false) { }
};
struct Derived: public Base {
using Base::Base;
};
int main() {
Derived d;
}
The inherited constructor will also be noexcept(false)
because as you quoted an inherited constructor will be noexcept(true)
by default
unless they are required to call a function that is noexcept(false)
When the Derived
constructor runs it will also call the Base
constructor which is noexcept(false)
, therefore, the Derived
constructor will also be noexcept(false)
.
This is evidenced by the following.
#include <iostream>
struct Base {
Base() noexcept(false) { }
};
struct Derived: public Base {
using Base::Base;
};
int main() {
std::cout << noexcept(Derived());
}
Outputs 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With