See it here.
The program is very mundane, like that:
#include <vector>
std::vector<int> bombs;
int main()
{
bombs.push_back(42); // compile errors
}
The diagnostics do not make much sense to me:
In file included from main.cpp:1:
In file included from
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/vector:60:
In file included from
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/stl_algobase.h:64:
In file included from
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/stl_pair.h:59:
In file included from
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/move.h:55:
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/type_traits:1061:48: error: '_Tp' does not refer to a value
: public __bool_constant<__is_assignable(_Tp, _Up)>
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/type_traits:1059:21: note: declared here
template<typename _Tp, typename _Up>
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/type_traits:1061:53: error: _Up does not refer to a value
: public __bool_constant<__is_assignable(_Tp, _Up)>
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/type_traits:1059:35: note: declared here
template<typename _Tp, typename _Up>
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/type_traits:1062:5:
error: expected class name
{ };
^
In file included from main.cpp:1:
In file included from
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/vector:63:
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/stl_uninitialized.h:128:70:
error: no member named value in std::is_assignable<int &, int &&>
const bool __assignable = is_assignable<_RefType2, _RefType1>::value;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/stl_uninitialized.h:289:19:
note: in instantiation of function template specialization
std::uninitialized_copy<std::move_iterator<int *>, int *> requested
here
{ return std::uninitialized_copy(__first, __last, __result); }
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/stl_uninitialized.h:310:19:
note: in instantiation of function template specialization
std::__uninitialized_copy_a<std::move_iterator<int *>, int *, int>
requested here
return std::__uninitialized_copy_a
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/vector.tcc:446:13: note: in instantiation of function template specialization std::__uninitialized_move_if_noexcept_a<int *, int *, std::allocator<int> > requested here
= std::__uninitialized_move_if_noexcept_a
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/vector.tcc:109:4:
note: in instantiation of function template specialization
std::vector<int, std::allocator<int> >::_M_realloc_insert<int>
requested here
_M_realloc_insert(end(), std::forward<_Args>(__args)...);
^
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/8.1.0/../../../../include/c++/8.1.0/bits/stl_vector.h:1091:9:
note: in instantiation of function template specialization
std::vector<int, std::allocator<int> >::emplace_back<int> requested
here
{ emplace_back(std::move(__x)); }
^
main.cpp:7:9: note: in instantiation of member function
std::vector<int, std::allocator<int> >::push_back requested here
bombs.push_back(42);
^
4 errors generated.
Same with g++ compiles without any issues. I can't really look at the
library headers that Clang at Coliru includes to program for to figure it out myself. Does anyone have any ideas what is wrong and how to overcome the issue?
I 100% wouldn't worry about this, it's just some weirdness at Coliru. It works perfectly at Wandbox, right back to Clang 3.1
According to the donations page, you can probably report this problem to [email address redacted].
Related
I'm trying to move the whole vector to another variable.
The following code block does not compile.
I thought that the call to std::move would force to use the Move-Constructor. Instead it seems like std::vector is using the Copy-Constructor that is deleted.
What's wrong here? How can I move all elements without copying them?
#include <vector>
class TheClass {
public:
TheClass(const TheClass&) = delete;
TheClass(TheClass&&) = default;
};
void fun2(const std::vector<TheClass> data) {
std::vector<TheClass> a = std::move(data);
a.size();
}
leads to:
clang++ -o /cplayground/cplayground /cplayground/code.cpp -I/cplayground/include -L/cplayground/lib -std=c++20 -O0 -Wall -no-pie -lm -pthread
In file included from /cplayground/code.cpp:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/vector:66:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:137:7: error: static_assert failed due to requirement 'is_constructible<TheClass, const TheClass &>::value' "result type must be constructible from value type of input range"
static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:325:19: note: in instantiation of function template specialization 'std::uninitialized_copy<__gnu_cxx::__normal_iterator<const TheClass *, std::vector<TheClass, std::allocator<TheClass> > >, TheClass *>' requested here
{ return std::uninitialized_copy(__first, __last, __result); }
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:558:9: note: in instantiation of function template specialization 'std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<const TheClass *, std::vector<TheClass, std::allocator<TheClass> > >, TheClass *, TheClass>' requested here
std::__uninitialized_copy_a(__x.begin(), __x.end(),
^
/cplayground/code.cpp:10:29: note: in instantiation of member function 'std::vector<TheClass, std::allocator<TheClass> >::vector' requested here
std::vector<TheClass> a = std::move(data);
^
In file included from /cplayground/code.cpp:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/vector:62:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_algo.h:62:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_tempbuf.h:60:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_construct.h:109:38: error: call to deleted constructor of 'TheClass'
{ ::new(static_cast<void*>(__p)) _Tp(std::forward<_Args>(__args)...); }
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:91:8: note: in instantiation of function template specialization 'std::_Construct<TheClass, const TheClass &>' requested here
std::_Construct(std::__addressof(*__cur), *__first);
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:150:2: note: in instantiation of function template specialization 'std::__uninitialized_copy<false>::__uninit_copy<__gnu_cxx::__normal_iterator<const TheClass *, std::vector<TheClass, std::allocator<TheClass> > >, TheClass *>' requested here
__uninit_copy(__first, __last, __result);
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:325:19: note: in instantiation of function template specialization 'std::uninitialized_copy<__gnu_cxx::__normal_iterator<const TheClass *, std::vector<TheClass, std::allocator<TheClass> > >, TheClass *>' requested here
{ return std::uninitialized_copy(__first, __last, __result); }
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:558:9: note: in instantiation of function template specialization 'std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<const TheClass *, std::vector<TheClass, std::allocator<TheClass> > >, TheClass *, TheClass>' requested here
std::__uninitialized_copy_a(__x.begin(), __x.end(),
^
/cplayground/code.cpp:10:29: note: in instantiation of member function 'std::vector<TheClass, std::allocator<TheClass> >::vector' requested here
std::vector<TheClass> a = std::move(data);
^
/cplayground/code.cpp:5:3: note: 'TheClass' has been explicitly marked deleted here
TheClass(const TheClass&) = delete;
^
2 errors generated.
You can't move something that is const (I mean, you can call std::move on it, but it won't allow you to move things). Remove that qualifier and (maybe) pass a rvalue reference:
void fun2(std::vector<TheClass>&& data)
{
std::vector<TheClass> a = std::move(data);
a.size();
}
Then :
std::vector<TheClass> vec;
fun2(std::move(vec));
Note that you may omit that &&(see https://godbolt.org/z/5M1f4j66r).
I realize nested std::any's are a bad idea. Nevertheless, I encountered something that's making me scratch my head and I'm just trying to understand why the compiler is choking. Consider the following line of code (assuming that the arg variable is a std::any containing another std::any):
auto result = std::any_cast<std::any>(arg);
That line compiles just fine. Now, consider this line, where I have a std::any containing a std::tuple that contains another std::any:
auto result = std::any_cast<std::tuple<std::any>>(arg);
Now, the compiler blows up. These are the errors I get:
In file included from /home/james/git/trogdor-pp/src/core/event/triggers/luaeventtrigger.cpp:1:
In file included from /home/james/git/trogdor-pp/src/core/include/trogdor/game.h:5:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:37:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:40:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/exception:144:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/nested_exception.h:40:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/move.h:55:
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:132:31: error: no member named 'value' in 'std::is_copy_constructible<std::tuple<std::any> >'
: public conditional<_B1::value, _B2, _B1>::type
~~~~~^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:170:17: note: in instantiation of template class 'std::__and_<std::is_copy_constructible<std::tuple<std::any> >, std::is_constructible<std::tuple<std::any>, const std::tuple<std::any> &> >' requested here
enable_if<__and_<is_copy_constructible<_Tp>,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:175:5: note: in instantiation of template type alias '__any_constructible' requested here
using __any_constructible_t =
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:181:56: note: in instantiation of template type alias '__any_constructible_t' requested here
__any_constructible_t<_Tp, _ValueType&&> = true,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:183:7: note: while substituting prior template arguments into non-type template parameter [with _ValueType = const std::tuple<std::any> &, _Tp = std::tuple<std::any>, _Mgr = std::any::_Manager_external<std::tuple<std::any> >]
any(_ValueType&& __value)
^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:884:56: note: while substituting deduced template arguments into function template 'any' [with _ValueType = const std::tuple<std::any> &, _Tp = (no value), _Mgr = (no value), $3 = (no value), $4 = (no value)]
: public __bool_constant<__is_constructible(_Tp, _Args...)>
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:884:32: note: (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
: public __bool_constant<__is_constructible(_Tp, _Args...)>
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:908:14: note: in instantiation of template class 'std::__is_copy_constructible_impl<std::tuple<std::any>, true>' requested here
: public __is_copy_constructible_impl<_Tp>
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:109:14: note: in instantiation of template class 'std::is_copy_constructible<std::tuple<std::any> >' requested here
: public conditional<_B1::value, _B1, _B2>::type
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:358:16: note: in instantiation of template class 'std::__or_<std::is_reference<std::tuple<std::any> >, std::is_copy_constructible<std::tuple<std::any> > >' requested here
{ return __or_<is_reference<_Tp>, is_copy_constructible<_Tp>>::value; }
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:481:26: note: in instantiation of function template specialization 'std::any::__is_valid_cast<std::tuple<std::any> >' requested here
static_assert(any::__is_valid_cast<_ValueType>(),
^
/home/james/git/trogdor-pp/src/core/event/triggers/luaeventtrigger.cpp:42:32: note: in instantiation of function template specialization 'std::any_cast<std::tuple<std::any> >' requested here
auto arg = std::any_cast<std::tuple<std::any>>(a);
^
In file included from /home/james/git/trogdor-pp/src/core/event/triggers/luaeventtrigger.cpp:1:
In file included from /home/james/git/trogdor-pp/src/core/include/trogdor/game.h:5:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:37:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/new:40:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/exception:144:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/nested_exception.h:40:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/move.h:55:
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:137:31: error: no member named 'value' in 'std::is_copy_constructible<std::tuple<std::any> >'
: public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
~~~~~^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:150:37: note: in instantiation of template class 'std::__and_<std::is_copy_constructible<std::tuple<std::any> >, std::__not_<std::is_constructible<std::tuple<std::any>, const std::tuple<std::any> &> >, std::__not_<std::__is_in_place_type<std::tuple<std::any> > > >' requested here
inline constexpr bool __and_v = __and_<_Bn...>::value;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:192:27: note: in instantiation of variable template specialization 'std::__and_v<std::is_copy_constructible<std::tuple<std::any> >, std::__not_<std::is_constructible<std::tuple<std::any>, const std::tuple<std::any> &> >, std::__not_<std::__is_in_place_type<std::tuple<std::any> > > >' requested here
enable_if_t<__and_v<is_copy_constructible<_Tp>,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:196:7: note: while substituting prior template arguments into non-type template parameter [with _ValueType = const std::tuple<std::any> &, _Tp = std::tuple<std::any>, _Mgr = std::any::_Manager_external<std::tuple<std::any> >]
any(_ValueType&& __value)
^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:884:56: note: while substituting deduced template arguments into function template 'any' [with _ValueType = const std::tuple<std::any> &, _Tp = (no value), _Mgr = (no value), $3 = (no value)]
: public __bool_constant<__is_constructible(_Tp, _Args...)>
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:884:32: note: while substituting deduced template arguments into function template 'tuple' [with _Dummy = (no value), $1 = (no value)]
: public __bool_constant<__is_constructible(_Tp, _Args...)>
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:902:14: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all)
: public is_constructible<_Tp, const _Tp&>
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:908:14: note: in instantiation of template class 'std::__is_copy_constructible_impl<std::tuple<std::any>, true>' requested here
: public __is_copy_constructible_impl<_Tp>
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:109:14: note: in instantiation of template class 'std::is_copy_constructible<std::tuple<std::any> >' requested here
: public conditional<_B1::value, _B1, _B2>::type
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:358:16: note: in instantiation of template class 'std::__or_<std::is_reference<std::tuple<std::any> >, std::is_copy_constructible<std::tuple<std::any> > >' requested here
{ return __or_<is_reference<_Tp>, is_copy_constructible<_Tp>>::value; }
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/any:481:26: note: in instantiation of function template specialization 'std::any::__is_valid_cast<std::tuple<std::any> >' requested here
static_assert(any::__is_valid_cast<_ValueType>(),
^
/home/james/git/trogdor-pp/src/core/event/triggers/luaeventtrigger.cpp:42:32: note: in instantiation of function template specialization 'std::any_cast<std::tuple<std::any> >' requested here
auto arg = std::any_cast<std::tuple<std::any>>(a);
I'm having a hard time unpacking all of that and figuring out what's wrong and how I can fix it.
EDIT: we've discovered in the comments that this code does not compile under G++ 9 and below, but compiles on G++ 10 and above, and also fails on clang 10 and below, but compiles on clang 11 and above. Does anybody have any guesses as to why this might be the case?
The key part is error: no member named 'value' in 'std::is_copy_constructible<std::tuple<std::any> >'
This is the compiler's way of complaining that the indicated object, the std::tuple, is not copy-constructible.
Your gcc does not believe, apparently, that std::tuplestd::any is copy-constructible. A tuple, in of itself, should be copy constructible if everything in the tuple is copy-constructible. Given that std::any is C++17, and gcc 9's C++17 support is incomplete, at least incomplete insofar as this part of C++17 goes (gcc 11's feature list still includes some C++17 features).
std::reference_wrapper should be copy-constructible, regardless of the contained type (it's just a pointer inside). However, when asserting that using
static_assert(std::is_copy_constructible<std::reference_wrapper<std::any> >::value, "!");
Clang terminates with a compile error from inside the STL, while GCC reports no problems. This is not the case with other types (I tested std::reference_wrapper<int> and std::any directly).
I have an example showing compilation in GCC and Clang at https://godbolt.org/z/7YwkWb.
As far as I understand it, even if the type given to std::is_copy_constructible is not copy-constructible, it should just give a compile-time false, rather than failing compilation.
What is the problem here? Is that a compiler bug or am I missing something?
The compile error from Clang is:
In file included from <source>:1:
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:132:31: error: no member named 'value' in 'std::is_copy_constructible<std::reference_wrapper<std::any> >'
: public conditional<_B1::value, _B2, _B1>::type
~~~~~^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/any:170:17: note: in instantiation of template class 'std::__and_<std::is_copy_constructible<std::reference_wrapper<std::any> >, std::is_constructible<std::reference_wrapper<std::any>, const std::reference_wrapper<std::any> &> >' requested here
enable_if<__and_<is_copy_constructible<_Tp>,
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/any:175:5: note: in instantiation of template type alias '__any_constructible' requested here
using __any_constructible_t =
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/any:181:56: note: in instantiation of template type alias '__any_constructible_t' requested here
__any_constructible_t<_Tp, _ValueType&&> = true,
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/any:183:7: note: while substituting prior template arguments into non-type template parameter [with _ValueType = const std::reference_wrapper<std::any> &, _Tp = std::reference_wrapper<std::any>, _Mgr = std::any::_Manager_internal<std::reference_wrapper<std::any> >]
any(_ValueType&& __value)
^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:921:56: note: while substituting deduced template arguments into function template 'any' [with _ValueType = const std::reference_wrapper<std::any> &, _Tp = (no value), _Mgr = (no value), $3 = (no value), $4 = (no value)]
: public __bool_constant<__is_constructible(_Tp, _Args...)>
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:933:14: note: in instantiation of template class 'std::is_constructible<std::reference_wrapper<std::any>, const std::reference_wrapper<std::any> &>' requested here
: public is_constructible<_Tp, const _Tp&>
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:939:14: note: in instantiation of template class 'std::__is_copy_constructible_impl<std::reference_wrapper<std::any>, true>' requested here
: public __is_copy_constructible_impl<_Tp>
^
<source>:12:20: note: in instantiation of template class 'std::is_copy_constructible<std::reference_wrapper<std::any> >' requested here
static_assert(std::is_copy_constructible<std::reference_wrapper<std::any> >::value, "!");
^
In file included from <source>:1:
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:137:31: error: no member named 'value' in 'std::is_copy_constructible<std::reference_wrapper<std::any> >'
: public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
~~~~~^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/any:192:27: note: in instantiation of template class 'std::__and_<std::is_copy_constructible<std::reference_wrapper<std::any> >, std::__not_<std::is_constructible<std::reference_wrapper<std::any>, const std::reference_wrapper<std::any> &> >, std::__not_<std::__is_in_place_type<std::reference_wrapper<std::any> > > >' requested here
enable_if_t<__and_<is_copy_constructible<_Tp>,
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/any:196:7: note: while substituting prior template arguments into non-type template parameter [with _ValueType = const std::reference_wrapper<std::any> &, _Tp = std::reference_wrapper<std::any>, _Mgr = std::any::_Manager_internal<std::reference_wrapper<std::any> >]
any(_ValueType&& __value)
^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:921:56: note: while substituting deduced template arguments into function template 'any' [with _ValueType = const std::reference_wrapper<std::any> &, _Tp = (no value), _Mgr = (no value), $3 = (no value)]
: public __bool_constant<__is_constructible(_Tp, _Args...)>
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:933:14: note: in instantiation of template class 'std::is_constructible<std::reference_wrapper<std::any>, const std::reference_wrapper<std::any> &>' requested here
: public is_constructible<_Tp, const _Tp&>
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/type_traits:939:14: note: in instantiation of template class 'std::__is_copy_constructible_impl<std::reference_wrapper<std::any>, true>' requested here
: public __is_copy_constructible_impl<_Tp>
^
<source>:12:20: note: in instantiation of template class 'std::is_copy_constructible<std::reference_wrapper<std::any> >' requested here
static_assert(std::is_copy_constructible<std::reference_wrapper<std::any> >::value, "!");
^
2 errors generated.
Compiler returned: 1
The error you see clearly states at the top that std::is_copy_constructible doesn't have a value member for the specialization you check. Now, the types you pass don't violate the contract of std::is_copy_constructible, so there is no risk of undefined behavior.
Which means only one thing, it's not a compiler issue, but a standard library implementation issue. Clang uses the default installed standard library implementation, which on the system godbolt is running is libstdc++ (the GNU implementation). This evidently causes the issue due to some possible soft incompatibility.
If you specify the -stdlib=libc++ option (libc++ is the LLVM implementation of the standard library) when building with Clang, then it accepts the code fine.
I have following code in C++ and it works perfectly fine on GCC, MSVC2015, Android NDK, ...
class JsonLongText {
private:
enum JsonToken {
JT_OBJECT,
JT_ARRAY,
JT_VARIABLE,
JT_EMPTY
};
typedef std::vector<JsonToken> JsonTokenStack;
JsonTokenStack m_OpenTokens;
....
JsonLongText() : m_IgnoreEmptyItems(true), m_RequireItemSeparator(false), m_PrettyPrint(false) {}
}
I sucessfully compiled it on MacOS 10.13 from commandline with XCode 9.2 as well. But after my system was upgraded from 10.13 to 10.13.4 and Xcode to version 9.3. I'm facing following errors:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2141:9: error: no matching constructor for
initialization of '__compressed_pair_elem<JsonLongText::JsonToken *, 0>'
: _Base1(std::forward<_Tp>(__t)), _Base2() {}
^ ~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:423:7: note: in instantiation of function template
specialization 'std::__1::__compressed_pair<JsonLongText::JsonToken *, std::__1::allocator<JsonLongText::JsonToken> >::__compressed_pair<long, true>'
requested here
__end_cap_(nullptr)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:473:5: note: in instantiation of member function
'std::__1::__vector_base<JsonLongText::JsonToken, std::__1::allocator<JsonLongText::JsonToken> >::__vector_base' requested here
vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
^
../Include/JsonLongText.h:162:2: note: in instantiation of member function 'std::__1::vector<JsonLongText::JsonToken,
std::__1::allocator<JsonLongText::JsonToken> >::vector' requested here
JsonLongText() : m_IgnoreEmptyItems(true), m_RequireItemSeparator(false), m_PrettyPrint(false) {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note: candidate constructor
(the implicit copy constructor) not viable: no known conversion from 'long' to 'const std::__1::__compressed_pair_elem<JsonLongText::JsonToken *, 0,
false>' for 1st argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note: candidate constructor
(the implicit move constructor) not viable: no known conversion from 'long' to 'std::__1::__compressed_pair_elem<JsonLongText::JsonToken *, 0, false>'
for 1st argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2050:3: note: candidate template ignored:
substitution failure [with _Up = long, $1 = void]
__compressed_pair_elem(_Up&& __u)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2055:3: note: candidate constructor template not
viable: requires 3 arguments, but 1 was provided
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2043:39: note: candidate constructor not viable:
requires 0 arguments, but 1 was provided
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2141:9: error: no matching constructor for
initialization of '__compressed_pair_elem<unsigned long *, 0>'
: _Base1(std::forward<_Tp>(__t)), _Base2() {}
^ ~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:423:7: note: in instantiation of function template
specialization 'std::__1::__compressed_pair<unsigned long *, std::__1::allocator<unsigned long> >::__compressed_pair<long, true>' requested here
__end_cap_(nullptr)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:473:5: note: in instantiation of member function
'std::__1::__vector_base<unsigned long, std::__1::allocator<unsigned long> >::__vector_base' requested here
vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
^
../Include/JsonLongText.h:162:2: note: in instantiation of member function 'std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >::vector'
requested here
JsonLongText() : m_IgnoreEmptyItems(true), m_RequireItemSeparator(false), m_PrettyPrint(false) {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note: candidate constructor
(the implicit copy constructor) not viable: no known conversion from 'long' to 'const std::__1::__compressed_pair_elem<unsigned long *, 0, false>' for
1st argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note: candidate constructor
(the implicit move constructor) not viable: no known conversion from 'long' to 'std::__1::__compressed_pair_elem<unsigned long *, 0, false>' for 1st
argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2050:3: note: candidate template ignored:
substitution failure [with _Up = long, $1 = void]
__compressed_pair_elem(_Up&& __u)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2055:3: note: candidate constructor template not
viable: requires 3 arguments, but 1 was provided
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2043:39: note: candidate constructor not viable:
requires 0 arguments, but 1 was provided
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
I tried to replace whole directory /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 with files from another Mac where is XCode 9.2. With these files the build of my project finishes sucessfully. It looks like libc++ in the current version of XCode is corrupted.
So, it's possible to downgrade version of XCode or to upgrade libc++?
EDIT:
Similar errors crop up when try to use regex. Following code (copied from cppreference):
// Simple regular expression matching
std::string fnames[] = {"foo.txt", "bar.txt", "baz.dat", "zoidberg"};
std::regex txt_regex("[a-z]+\\.txt");
for (const auto &fname : fnames) {
std::cout << fname << ": " << std::regex_match(fname, txt_regex) << '\n';
}
compile command:
g++ -std=c++11 -DSTATIC_LIB -g -I . -I ../../../../openssl/iOS/include -o out/Expression.o -c Expression.cpp
cause:
In file included from Expression.cpp:113:
In file included from ./StdAfx.h:23:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2051:9: error: cannot initialize a member subobject
of type 'std::__1::sub_match<const char *> *' with an rvalue of type 'long'
: __value_(_VSTD::forward<_Up>(__u)){};
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2151:9: note: in instantiation of function template
specialization 'std::__1::__compressed_pair_elem<std::__1::sub_match<const char *> *, 0, false>::__compressed_pair_elem<long, void>' requested here
: _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:432:7: note: in instantiation of function template
specialization 'std::__1::__compressed_pair<std::__1::sub_match<const char *> *, std::__1::allocator<std::__1::sub_match<const char *> >
>::__compressed_pair<long, const std::__1::allocator<std::__1::sub_match<const char *> > &>' requested here
__end_cap_(nullptr, __a)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:485:11: note: in instantiation of member function
'std::__1::__vector_base<std::__1::sub_match<const char *>, std::__1::allocator<std::__1::sub_match<const char *> > >::__vector_base' requested here
: __base(__a)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:5355:7: note: in instantiation of member function
'std::__1::vector<std::__1::sub_match<const char *>, std::__1::allocator<std::__1::sub_match<const char *> > >::vector' requested here
: __matches_(__a),
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2988:34: note: in instantiation of member function
'std::__1::match_results<const char *, std::__1::allocator<std::__1::sub_match<const char *> > >::match_results' requested here
match_results<const _CharT*> __m;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2978:5: note: (skipping 4 contexts in backtrace; use
-ftemplate-backtrace-limit=0 to see all)
__lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:4098:35: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_term<const char *>' requested here
_ForwardIterator __temp = __parse_term(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:4074:31: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_alternative<const char *>' requested here
_ForwardIterator __temp = __parse_alternative(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:3026:19: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_ecma_exp<const char *>' requested here
__first = __parse_ecma_exp(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2522:10: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse<const char *>' requested here
{__parse(__p, __p + __traits_.length(__p));}
^
Expression.cpp:3356:16: note: in instantiation of member function 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::basic_regex' requested here
std::regex txt_regex("[a-z]+\\.txt");
^
In file included from Expression.cpp:113:
In file included from ./StdAfx.h:23:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2051:9: error: cannot initialize a member subobject
of type 'std::__1::__state<char> *' with an rvalue of type 'long'
: __value_(_VSTD::forward<_Up>(__u)){};
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2141:9: note: in instantiation of function template
specialization 'std::__1::__compressed_pair_elem<std::__1::__state<char> *, 0, false>::__compressed_pair_elem<long, void>' requested here
: _Base1(std::forward<_Tp>(__t)), _Base2() {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:423:7: note: in instantiation of function template
specialization 'std::__1::__compressed_pair<std::__1::__state<char> *, std::__1::allocator<std::__1::__state<char> > >::__compressed_pair<long, true>'
requested here
__end_cap_(nullptr)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:473:5: note: in instantiation of member function
'std::__1::__vector_base<std::__1::__state<char>, std::__1::allocator<std::__1::__state<char> > >::__vector_base' requested here
vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:5536:21: note: in instantiation of member function
'std::__1::vector<std::__1::__state<char>, std::__1::allocator<std::__1::__state<char> > >::vector' requested here
vector<__state> __states;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2990:29: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__match_at_start_ecma<std::__1::allocator<std::__1::sub_match<const char *>
> >' requested here
bool __matched = __exp_.__match_at_start_ecma(
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2978:5: note: (skipping 4 contexts in backtrace; use
-ftemplate-backtrace-limit=0 to see all)
__lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:4098:35: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_term<const char *>' requested here
_ForwardIterator __temp = __parse_term(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:4074:31: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_alternative<const char *>' requested here
_ForwardIterator __temp = __parse_alternative(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:3026:19: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_ecma_exp<const char *>' requested here
__first = __parse_ecma_exp(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2522:10: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse<const char *>' requested here
{__parse(__p, __p + __traits_.length(__p));}
^
Expression.cpp:3356:16: note: in instantiation of member function 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::basic_regex' requested here
std::regex txt_regex("[a-z]+\\.txt");
^
In file included from Expression.cpp:113:
In file included from ./StdAfx.h:23:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2141:9: error: no matching constructor for
initialization of '__compressed_pair_elem<std::__1::sub_match<const char *> *, 0>'
: _Base1(std::forward<_Tp>(__t)), _Base2() {}
^ ~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:423:7: note: in instantiation of function template
specialization 'std::__1::__compressed_pair<std::__1::sub_match<const char *> *, std::__1::allocator<std::__1::sub_match<const char *> >
>::__compressed_pair<long, true>' requested here
__end_cap_(nullptr)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:473:5: note: in instantiation of member function
'std::__1::__vector_base<std::__1::sub_match<const char *>, std::__1::allocator<std::__1::sub_match<const char *> > >::__vector_base' requested here
vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:1326:5: note: in instantiation of member function
'std::__1::vector<std::__1::sub_match<const char *>, std::__1::allocator<std::__1::sub_match<const char *> > >::vector' requested here
__state()
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:5545:28: note: in instantiation of member function
'std::__1::__state<char>::__state' requested here
__states.push_back(__state());
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2990:29: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__match_at_start_ecma<std::__1::allocator<std::__1::sub_match<const char *>
> >' requested here
bool __matched = __exp_.__match_at_start_ecma(
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2978:5: note: (skipping 4 contexts in backtrace; use
-ftemplate-backtrace-limit=0 to see all)
__lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:4098:35: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_term<const char *>' requested here
_ForwardIterator __temp = __parse_term(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:4074:31: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_alternative<const char *>' requested here
_ForwardIterator __temp = __parse_alternative(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:3026:19: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_ecma_exp<const char *>' requested here
__first = __parse_ecma_exp(__first, __last);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/regex:2522:10: note: in instantiation of function template
specialization 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse<const char *>' requested here
{__parse(__p, __p + __traits_.length(__p));}
^
Expression.cpp:3356:16: note: in instantiation of member function 'std::__1::basic_regex<char, std::__1::regex_traits<char> >::basic_regex' requested here
std::regex txt_regex("[a-z]+\\.txt");
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note: candidate constructor
(the implicit copy constructor) not viable: no known conversion from 'long' to 'const std::__1::__compressed_pair_elem<std::__1::sub_match<const char
*> *, 0, false>' for 1st argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note: candidate constructor
(the implicit move constructor) not viable: no known conversion from 'long' to 'std::__1::__compressed_pair_elem<std::__1::sub_match<const char *> *,
0, false>' for 1st argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2050:3: note: candidate template ignored:
substitution failure [with _Up = long, $1 = void]
__compressed_pair_elem(_Up&& __u)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2055:3: note: candidate constructor template not
viable: requires 3 arguments, but 1 was provided
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2043:39: note: candidate constructor not viable:
requires 0 arguments, but 1 was provided
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
I can now reproduce your exact regex error, verbatim, on my machine.
The trick is to redefine nullptr to 0u as a preprocessor symbol, before including the vector standard library header (which regex depends on):
#define nullptr 0l
#include <regex>
#include <iostream>
int main ()
{
std::string fnames[] = {"foo.txt", "bar.txt", "baz.dat", "zoidberg"};
std::regex txt_regex("[a-z]+\\.txt");
for (const auto &fname : fnames)
std::cout << fname << ": " << std::regex_match(fname, txt_regex) << '\n';
}
In light of the above, I now think your issue is a case of header preprocessor namespace pollution: some header, somewhere in the inclusion chain of your failing translation unit, likely defines a nullptr macro this way, which causes errors with the implementation of the standard library shipped with Xcode 9.3, but (I speculate) not with other implementations, for some reason.
I would suggest inspecting the preprocessor output using g++ -E, and check on what becomes of the offending code at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:432, where I believe the errors are being initially triggered.
Alternatively, you can try always including vector first in your translation units. I suspect this would allow you to dodge the issue, while you keep looking for the root cause.
Good luck!
I just had the problem,xcode version 12.4,carefully check my code and find that there are a define: # define nullptr (NULL).When removing this code, the build succeeds again.
I'm migrating from v8 3.x to 4.y and I'm having problems with one of the functions defined in one of my header file.
//JavascriptBase.h
namespace Company {
class Base {
protected:
void registerHandler(v8::Persistent<v8::Function>& func) {
user_functions_.push_back(func);
}
private:
std::vector<v8::Persistent<v8::Function>> user_functions_;
}
}
When I try to compile I get the following errors:
third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:667:53: error: assigning to 'v8::Object *volatile' from incompatible type 'v8::Primitive *'
while (false) { *(static_cast<O* volatile*>(0)) = static_cast<Primitive*>(0); };
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:663:5: note: in instantiation of function template specialization 'v8::NonCopyablePersistentTraits<v8::Function>::Uncompilable<v8::Object>' requested here
Uncompilable<Object>();
^
third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:7175:6: note: in instantiation of function template specialization 'v8::NonCopyablePersistentTraits<v8::Function>::Copy<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >' requested here
M::Copy(that, this);
^
third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:729:5: note: in instantiation of function template specialization 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >::Copy<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >' requested here
Copy(that);
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/ext/new_allocator.h:120:23: note: in instantiation of member function 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >::Persistent' requested here
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/bits/alloc_traits.h:254:8: note: in instantiation of function template specialization '__gnu_cxx::new_allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > >::construct<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, const v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > &>' requested here
{ __a.construct(__p, std::forward<_Args>(__args)...); }
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/bits/alloc_traits.h:393:4: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > > >::_S_construct<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, const v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > &>' requested here
{ _S_construct(__a, __p, std::forward<_Args>(__args)...); }
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/bits/stl_vector.h:905:21: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > > >::construct<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, const v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > &>' requested here
_Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
^
./Company/JavaScriptBase.h:84:21: note: in instantiation of member function 'std::vector<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, std::allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > > >::push_back' requested here
user_functions_.push_back(func);
^
1 error generated.
I've done some googling and found that Persistent objects aren't assignable but I'm not sure what to do with this information. Any help would be appreciated.
If they aren't assignable then you (obviously) can't assign them. And since std::vector<> relies on copying values using the assignment operator, your approach won't work.
You can however store pointers to them instead, since copying pointers of anything is well defined.
You can make a copyable persistent with this "typedef"
using CopyablePersistent = v8::Persistent<T, v8::CopyablePersistentTraits<T>>;
This assumes it's inside a templated class, but you can make the T whatever you want.
edit: apparently this is a "very bad" thing to do, but I don't know why.