According to the answer of this question, a default move constructor can be defined as noexcept
under certain conditions. For instance, the following class generates a noexcept
move constructor:
class C {};
According to the answer to this question, a move constructor defined with the = default
specifier would generate the same one as an implicitly defined move constructor. So, if I correctly understand it, the following class should generate a noexcept
move constructor:
class D {
D(D&&) = default;
};
To check that, I used the std::is_nothrow_move_constructible
function to see if C
and D
have a noexcept
move constructor:
#include <type_traits>
int main() {
static_assert(std::is_nothrow_move_constructible<C>::value, "C should be noexcept MoveConstructible");
static_assert(std::is_nothrow_move_constructible<D>::value, "D should be noexcept MoveConstructible");
return 0;
}
When I compile, I have got this error:
$ g++ toy.cpp -o toy
toy.cpp: In function ‘int main()’:
toy.cpp:16:5: error: static assertion failed: D should be noexcept MoveConstructible
static_assert(std::is_nothrow_move_constructible<D>::value, "D should be noexcept MoveConstructible");
^~~~~~~~~~~~~
Why my D
move constructor is not noexcept
?
I also tried with clang and I have got the same error. Here are the informations about my compilers:
$ g++ --version
g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ clang++8 --version
clang version 8.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
Aucun commentaire:
Enregistrer un commentaire