Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::reference_wrapper上的类型特征<;标准::任何>;_C++_Gcc_Clang_C++17 - Fatal编程技术网

C++ std::reference_wrapper上的类型特征<;标准::任何>;

C++ std::reference_wrapper上的类型特征<;标准::任何>;,c++,gcc,clang,c++17,C++,Gcc,Clang,C++17,std::reference_wrapper应该是可复制构造的,而不考虑包含的类型(它只是内部的指针)。然而,当断言使用 static_assert(std::is_copy_constructible<std::reference_wrapper<std::any> >::value, "!"); 您看到的错误在顶部清楚地指出,std::is\u copy\u constructible没有您检查的专门化的值成员。现在,您传递的类型不会违反std::is\u copy

std::reference_wrapper
应该是可复制构造的,而不考虑包含的类型(它只是内部的指针)。然而,当断言使用

static_assert(std::is_copy_constructible<std::reference_wrapper<std::any> >::value, "!");

您看到的错误在顶部清楚地指出,
std::is\u copy\u constructible
没有您检查的专门化的
值成员。现在,您传递的类型不会违反
std::is\u copy\u constructible
的约定,因此不存在未定义行为的风险

这意味着只有一件事,这不是编译器的问题,而是标准库实现的问题。Clang使用默认安装的标准库实现,该实现在运行的系统
godbolt
上是
libstdc++
(GNU实现)。由于某些可能的软不兼容性,这显然会导致问题


如果在使用Clang构建时指定
-stdlib=libc++
选项(
libc++
是标准库的LLVM实现),则它可以接受代码。请在问题中包含编译器错误。关于“…而不是编译失败”:静态断言的全部要点是在编译时失败,如果您只想查看值,请不要将其放入静态断言用户463035818:您完全正确。但是Clang中的编译不会失败,因为
静态断言失败。如果我删除
static\u assert
或否定参数,它也会失败。问题是,对
static\u assert
的(constexpr)参数求值时出错。是的,我只是认为
static\u assert
有点模糊,您的句子有点错误/有点误导。如果您给
std::is_copy_constructible
的类型不是copy constructible,则编译时将为false,并且代码将在编译时失败(因为静态断言),这是有意义的。我没有想到STL。然而:Clang难道不能用标准库的GNU实现进行编译吗?@ephimetheus——通常是这样。每个标准库版本都针对一个编译器进行了更多的定制。有时候,它会引起问题,就像你看到的。
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