मैं जीसीसी 7 पाया गारंटी प्रतिलिपि इलिजन लागू किया गया है, और मैं wandbox में नीचे दिए गए कोड की कोशिश की:गारंटी प्रतिलिपि इलिजन और Nonmoveable {Nonmoveable {}}
#include <iostream>
struct NonMovable
{
NonMovable() noexcept = default;
NonMovable(NonMovable&&) noexcept = delete;
NonMovable& operator=(NonMovable&&) noexcept = delete;
};
NonMovable Make()
{
return {};
}
int main()
{
//[[maybe_unused]] const auto x = Make();
//const auto z = NonMovable{};
[[maybe_unused]] const auto y = NonMovable{NonMovable{}};
}
और मैं त्रुटि संकलन मिल गया:
prog.cc: In function 'int main()':
prog.cc:20:60: error: use of deleted function 'NonMovable::NonMovable(NonMovable&&)'
[[maybe_unused]] const auto y = NonMovable{NonMovable{}};
^
prog.cc:6:5: note: declared here
NonMovable(NonMovable&&) noexcept = delete;
^~~~~~~~~~
cppreference के अनुसार:
In initialization, if the initializer expression is a prvalue and the cv-unqualified version of the source type is the same class as the class of the destination, the initializer expression is used to initialize the destination object:
T x = T(T(T())); // only one call to default constructor of T, to initialize x
तो मुझे लगता है यह होना चाहिए equ अल से const Movable y{};
। क्या गलत है?
ऐसा लगता है कि यह जीसीसी का एक बग है। कोड जीसीसी के नए निर्माण पर अच्छी तरह से संकलित करता है। – Cu2S