我从一位同事那里收到了以下代码,并使用Boost::Signal2 2和lambda表达式将其分解为最小值。它使用g++ 6.x和g++ 5.4.1编译(后者使用参数-std=c++11)。
它应该打印i: 5(应该是5)
使用gcc 6.4.1 (或6.1.1)交叉编译器arm32 (arm-cortexa15 15-linux-gnueabihf-g++)并在此系统上运行,输出为i: 0(应为5)。
其他体系结构(x86_64)和编译器(gcc 5.4.1)按预期工作。
当我改变代码使用一个信号,而不是一个插槽,一切都好。
我的问题是:
代码:
#include <exception>
#include <iostream>
#include <boost/signals2.hpp>
class LogBuffer : public std::streambuf
{
public:
LogBuffer()
{
}
char m_buf[242 - 20];
};
namespace boost
{
void assertion_failed(char const * p_expr,
char const *,
char const *, long)
{
std::cerr << "FAILED: " << p_expr << std::endl;
}
void assertion_failed_msg(char const *,
char const * msg,
char const *,
char const *, long)
{
std::cerr << "FAILED: " << msg << std::endl;
}
} // namespace boost
void myfunction(void)
{
{
LogBuffer b;
std::cout << "LogBuffer size: " << sizeof(LogBuffer) << std::endl;
}
int i=5;
std::cout << i << std::endl;
auto lambda = [i] { std::cerr << "i: " << i << " (should be 5)" << std::endl; };
boost::signals2::signal<void()>::slot_type slot{lambda};
slot();
}
int main(int argc, char *argv[])
{
myfunction();
} 编译和运行提供了以下输出:
arm-cortexa15-linux-gnueabihf-g++ (GCC) 6.4.1 20170811
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Linux fctj-4a 4.4.109-g68c6f3c-fsm4_axm #1 SMP PREEMPT Fri Feb 2 05:37:09 UTC 2018 armv7l GNU/Linux
LogBuffer size: 256
5
i: 0 (should be 5)发布于 2018-02-15 23:46:26
看上去像个虫子。
你能减少复制人吗?说,
std::cout尚未初始化//可用时获得断言),会发生什么?如果你把它减少到最简单的核心,并且仍然有故障,你至少会知道是在Boost还是GCC的时候提交一个bug。
发布于 2018-02-16 07:28:23
我已经这样做了:
其他人也会跟着做。我不知道如何轻松移除signals2头
雷纳
https://stackoverflow.com/questions/48811101
复制相似问题