Reputation: 273
I get errors when compiling this simple code and if I remove the noexcept I don't get the error:
#include<vector>
#include<string>
class Foo
{
public:
protected:
Foo(Foo&&) noexcept = default;
Foo& operator=(Foo&&) noexcept = default;
Foo()
{
}
private:
std::vector<std::string> vectorFoo_;
};
This is the errors I get, I understand it is in the instantiation of the exception specification, but I doubt the std::string is not nothrow move constructible,.. the first error make me think there is a bug.
In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: /usr/local/bin/../lib/c++/v1/vector:575:67: error: no member named 'value' in 'std::__1::is_nothrow_move_constructible, std::__1::allocator > > >' NOEXCEPT(is_nothrow_move_constructible::value); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:264: /usr/local/bin/../lib/c++/v1/__config:325:34: note: expanded from macro 'NOEXCEPT' define NOEXCEPT(x) noexcept(x) ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:29:29: note: in instantiation of exception specification for 'vector' requested here std::vector vectorFoo_; ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:265: In file included from /usr/local/bin/../lib/c++/v1/__bit_reference:15: In file included from /usr/local/bin/../lib/c++/v1/algorithm:624: /usr/local/bin/../lib/c++/v1/type_traits:2676:53: note: in instantiation of template class 'std::__1::add_rvalue_reference, std::__1::allocator > > >' requested here : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<Tp>::type> ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: /usr/local/bin/../lib/c++/v1/vector:575:20: note: in instantiation of template class 'std::_1::is_nothrow_move_constructible, std::__1::allocator > > >' requested here NOEXCEPT(is_nothrow_move_constructible::value); ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:264: /usr/local/bin/../lib/c++/v1/__config:325:34: note: expanded from macro 'NOEXCEPT' define NOEXCEPT(x) noexcept(x) ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:29:29: note: in instantiation of exception specification for 'vector' requested here std::vector vectorFoo_; ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: /usr/local/bin/../lib/c++/v1/vector:582:58: error: no member named 'value' in 'std::__1::is_nothrow_move_assignable, std::__1::allocator > > >' is_nothrow_move_assignable::value); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:264: /usr/local/bin/../lib/c++/v1/__config:325:34: note: expanded from macro 'NOEXCEPT' define NOEXCEPT(x) noexcept(x) ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:29:29: note: in instantiation of exception specification for 'operator=' requested here std::vector vectorFoo_; ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:265: In file included from /usr/local/bin/../lib/c++/v1/__bit_reference:15: In file included from /usr/local/bin/../lib/c++/v1/algorithm:624: /usr/local/bin/../lib/c++/v1/type_traits:2760:45: note: in instantiation of template class 'std::__1::add_lvalue_reference, std::__1::allocator > > >' requested here : public is_nothrow_assignableTp>::type, ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: /usr/local/bin/../lib/c++/v1/vector:582:14: note: in instantiation of template class 'std::_1::is_nothrow_move_assignable, std::__1::allocator > > >' requested here is_nothrow_move_assignable::value); ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:264: /usr/local/bin/../lib/c++/v1/__config:325:34: note: expanded from macro 'NOEXCEPT' define NOEXCEPT(x) noexcept(x) ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:29:29: note: in instantiation of exception specification for 'operator=' requested here std::vector vectorFoo_; ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:265: In file included from /usr/local/bin/../lib/c++/v1/__bit_reference:15: In file included from /usr/local/bin/../lib/c++/v1/algorithm:624: /usr/local/bin/../lib/c++/v1/type_traits:2676:53: note: in instantiation of template class 'std::__1::add_rvalue_reference, std::__1::allocator > > >' requested here : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<Tp>::type> ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: /usr/local/bin/../lib/c++/v1/vector:575:20: note: in instantiation of template class 'std::_1::is_nothrow_move_constructible, std::__1::allocator > > >' requested here NOEXCEPT(is_nothrow_move_constructible::value); ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4: In file included from /usr/local/bin/../lib/c++/v1/vector:264: /usr/local/bin/../lib/c++/v1/__config:325:34: note: expanded from macro 'NOEXCEPT' define NOEXCEPT(x) noexcept(x) ^ In file included from /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1: /Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:29:29: note: in instantiation of exception specification for 'vector' requested here std::vector vectorFoo_;
My compiler is clang from the top of tree. What am-I doing wrong?
Thanks
Update The error on Coliru. It seam that if I don't specify libc++ and instead use stdlibc++ it compiles. It is starting to look alot like a bug in libc++.
Upvotes: 3
Views: 793
Reputation: 16690
The code is fine. (and, interestingly enough, so is libc++)
This turns out to be a bug in clang; in fact, recent versions of clang crash when attempting to compile this code.
A patch fixing this in clang is currently being tested and will be part of the 3.4 release. If you can't wait that long, then you should be able to get a fixed version of clang "really soon now" if you are willing to build it from source.
Thanks to Alp from Nuanti for tracking down the clang bug.
Upvotes: 5
Reputation: 393613
My first assumption was, this might be because the move-assignment operator for std::string
isn't noexcept (need to check see below).
At least, clang and gcc seem to like this better:
Bar& operator = (Bar&&)
noexcept(
noexcept(std::declval<std::string>() = std::string())
) = default;
Now, on Foo clang and gcc don't quite agree, but here's Clang live on coliru
More food for thought: The standard appears to explicitely specify the assignment operator (as well as move constructor) for std::string as noexcept
: § 21.4.2
Upvotes: 3