Why is the move constructor neither declared nor deleted with clang?

前端 未结 2 933
挽巷
挽巷 2020-12-08 11:19

Consider the following classes.

struct with_copy {
    with_copy() = default;
    with_copy(with_copy const&) {}
    with_copy& operator=(with_copy c         


        
2条回答
  •  感情败类
    2020-12-08 11:49

    I'm not quite sure what you tested but it foo is surely both move assignable and move constructible. Admittedly, this doesn't say anything about a move constructor or a move assignment being accessible, just that construction or assignment from an rvalue works. Both clang (clang version 3.5 (trunk 196718)) and gcc (gcc version 4.9.0 20131031 (experimental) (GCC)) agree with this assessment. This is the complete source I tried:

    #include 
    #include 
    #include 
    
    struct with_copy {
        with_copy() = default;
        with_copy(with_copy const&) {}
        with_copy& operator=(with_copy const&) { return *this; }
    };
    
    struct foo {
        with_copy c;
        std::unique_ptr p;
    };
    
    int main()
    {
        std::cout << "move constructible: "
                  << std::is_move_constructible::value << '\n';
        std::cout << "move assignable: "
                  << std::is_move_assignable::value << '\n';
        foo f0;
        foo f1 = std::move(f0);
        f0 = std::move(f1);
    }
    

提交回复
热议问题