0
class Base
{
public:
     Base(Base&&) = default;
};

class Derived: public Base
{    

public:
    Derived(Derived&&)  = default;

};

int main()
{
    static_assert(std::is_nothrow_move_constructible_v<Derived>, "Error noexcept");
}

In this code even if neither Derived nor Base declared move constructor noexcept but still this passes static assert on std::is_nothrow_move_constructible_v<Derived>. Why?

gaurav bharadwaj
  • 1,669
  • 1
  • 12
  • 29
  • Does this answer your question? [What are all the member-functions created by compiler for a class? Does that happen all the time?](https://stackoverflow.com/questions/3734247/what-are-all-the-member-functions-created-by-compiler-for-a-class-does-that-hap) – MicroVirus Sep 02 '21 at 18:14
  • @MicroVirus No. I know all special member function provide/implemented by compiler but my question is different. Please see code example. – gaurav bharadwaj Sep 02 '21 at 18:16
  • 1
    If you make `Base(Base&&) noexcept(false) = default;` at least `clang++` will refuse it. If you also make `Derived(Derived&&) noexcept(false) = default;` MSVC will also refuse it. `g++` accepts both :-) – Ted Lyngmo Sep 02 '21 at 19:03
  • @TedLyngmo so If I did not write noexcept in move constructor and ask compiler to provide `default` implementation. It will always take noexcept(true)? – gaurav bharadwaj Sep 03 '21 at 14:12
  • 1
    @gauravbharadwaj No, it depends on if the parent class too. [example](https://godbolt.org/z/G4KzKo3zK) – Ted Lyngmo Sep 03 '21 at 14:34

0 Answers0