这是对std::bind的错误使用还是编译器错误?
Is this incorrect use of std::bind or a compiler bug?
我正在使用最新的快照构建的clang与最新的TDM-Gcc头文件和库。编译时(使用-std=c++11标志):
#include <functional>
#include <iostream>
class Foo
{
public:
void Bar(int x)
{
std::cout << x << std::endl;
}
};
int main()
{
Foo foo;
auto f = std::bind(&Foo::Bar, &foo, 5);
f();
return 0;
}
我得到这些错误:
In file included from Test.cpp:1:
C:DevEnvLLVM38libgccmingw325.1.0includec++functional:1426:7: error: static_assert failed "Wrong number of arguments for pointer-to-member"
static_assert(_Varargs::value
^ ~~~~~~~~~~~~~~~
C:DevEnvLLVM38libgccmingw325.1.0includec++functional:1440:7: note: in instantiation of template class 'std::_Bind_check_arity<void (Foo::*)(int) __attribute__((thiscall)), Foo *, int>' requested here
: _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
^
C:DevEnvLLVM38libgccmingw325.1.0includec++functional:1461:5: note: in instantiation of template class 'std::_Bind_helper<false, void (Foo::*)(int) __attribute__((thiscall)), Foo *, int>' requested here
_Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
^
Test.cpp:16:14: note: while substituting deduced template arguments into function template 'bind' [with _Func = void (Foo::*)(int) __attribute__((thiscall)), _BoundArgs = <Foo *, int>]
auto f = std::bind(&Foo::Bar, &foo, 5);
^
Test.cpp:16:14: error: no matching function for call to 'bind'
auto f = std::bind(&Foo::Bar, &foo, 5);
^~~~~~~~~
C:DevEnvLLVM38libgccmingw325.1.0includec++functional:1490:5: note: candidate template ignored: couldn't infer template argument '_Result'
bind(_Func&& __f, _BoundArgs&&... __args)
^
C:DevEnvLLVM38libgccmingw325.1.0includec++functional:1462:5: note: candidate template ignored: substitution failure [with _Func = void (Foo::*)(int) __attribute__((thiscall)), _BoundArgs = <Foo *, int>]
bind(_Func&& __f, _BoundArgs&&... __args)
^
2 errors generated.
是我滥用std::bind还是这是一些奇怪的编译错误?使用TDM Gcc似乎可以很好地编译。
这段代码很好。
除非你做了一些奇怪的事情或者你的安装不支持,否则你的工具链有一个错误。
对我来说,它看起来不考虑std::bind
的第二个参数是"这个指针",并认为你实际上传递了两个参数给Foo::Bar
(你不是),这是你不能的。
下一步是向工具链的维护者提出这个问题。
见https://llvm.org/bugs/show_bug.cgi?id=24372 .
相关文章:
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 重载方法的方式会在使用临时调用时生成编译器错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 有没有办法让编译器在我放置字符串而不是 nlohmann::json 对象时抛出错误?
- 致命错误 C1001 :vs2017 15.8.4 的内部错误(编译器文件"msc1.cpp",第
- C++2440错误-编译器认为字符串是常量字符
- Clang 错误 – 编译器错误或缺少一些细节?
- 视觉C++ 2017 错误?编译器优化表达式
- 配置:错误:C++编译器无法创建可执行文件
- PHP PDO_ODBC配置:错误:C 编译器无法创建可执行文件
- 致命错误 C1001:内部编译器错误(编译器文件"MSC1.cpp",第 1794 行)
- 错误:编译器限制达到简单hello world程序的堆限制
- c++链接错误:编译器找不到函数的定义
- 生成 CImg 时出现致命错误(编译器限制)
- 抛出对齐类型时出现 Clang 运行时错误.编译器错误