我试图用g ++ 4.8重新编译一个巨大的遗留应用程序,以便调试glibc detected memory corruption
问题(使用AddressSanitizer)。以前我们使用g ++ 4.4.7。升级到G ++ 4.8 - exception_ptr.h不支持异常传播
但是,编译失败:
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/bits/exception_ptr.h:40:4: error: #error This platform does not support exception propagation.
在编译自定义异常处理程序(我猜)。自定义异常处理程序只在一个地方使用exception_ptr
:
void reportOtherException(void) const
{
std::exception_ptr p = std::current_exception();
std::string s = (p != 0 ? p.__cxa_exception_type()->name() : "null");
printf("DvMain Bad Exception: '%s'\n", s.c_str());
mErrorReporter(0, DvLog::WARNING, 0, Dv::NO_PROFILE, 0, DvLog::UNHANDLED_OTHER_EXCEPTION);
}
而且reportOtherException()
这样使用:
try
{
// Catch and log uncaught exceptions, then exit.
catch (const std::bad_exception& e) { exHandler.reportBadException(e); }
catch (const std::exception& e) { exHandler.reportStandardException(e); }
catch (...) { exHandler.reportOtherException(); }
}
我很新的C++,不知道是什么错误,即使手段。使用4.4.7并且不适用于4.8。
什么需要改变什么指针来编译4.8?
编辑我
下面是一些额外的信息:
g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
最小码
DvComDefaultExceptionHandler_test.h
#include "DvCommon.h"
#include "evt/DvEvt.h"
#include "log/DvLog.h"
#include "com/DvComErrorReporter.h"
#include <new>
#include <exception>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include <bits/exception_ptr.h>
class DvComDefaultExceptionHandler
{
public:
DvComDefaultExceptionHandler(const DvComErrorReporter& er) {}
~DvComDefaultExceptionHandler() { }
void reportOtherException(void) const
{
std::exception_ptr p = std::current_exception();
}
private:
static const DvComDefaultExceptionHandler* mpInstance;
};
DvComDefaultExceptionHandler_test.cpp
#include "DvCommon.h"
#include "com/DvComDefaultExceptionHandler_test.h"
// Pointer to the single instance of the DvComDefaultExceptionHandler class.
const DvComDefaultExceptionHandler*
DvComDefaultExceptionHandler::mpInstance = 0;
编译命令和输出
g++ -c -g -O0 -DDEBUG -Wall -Wextra -Wno-sign-compare -Wcast-align
--ftemplate-depth-32 -march=native -ggdb -fPIC -Iinclude -I../../include
-I../../src -I/usr/include/libxml2 -D_GNU_SOURCE
-I/mnt/swdevel/DVMon/source_build/ext/ACE -D__ACE_INLINE__
-I/usr/local/include -I/usr/lib/qt-3.3/include
-o DvComDefaultExceptionHandler.o DvComDefaultExceptionHandler_test.cpp
In file included from ../../include/com/DvComDefaultExceptionHandler_test.h:76:0,
from DvComDefaultExceptionHandler_test.cpp:13:
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/bits/exception_ptr.h:40:4: error: #error This platform does not support exception propagation.
# error This platform does not support exception propagation.
EDIT II
跟踪通过包括文件归结为__GCC_ATOMIC_INT_LOCK_FREE的值。运行这个简单的程序打印'2'作为__GCC_ATOMIC_INT_LOCK_FREE的值。
int
main(int argc, char **argv)
{
printf("__GCC_ATOMIC_INT_LOCK_FREE = %d\n", __GCC_ATOMIC_INT_LOCK_FREE);
}
G ++ VERSION:
$ g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
EDIT II
我已经与克++ 6.3.1尝试过,上一个CentOS 7 VM上运行。仍然是同样的问题。
源文件 - 一个行仅
#include <bits/exception_ptr.h>
编译命令:g++ -c -o test.o test.cpp
我无法在Red Hat Enterprise Linux 6.9上用DTS 2重现这一点。请用'devtoolset-2-gcc-C++'软件包版本来修改你的文章,一个简单的例子(它可能是一些'#include'指令触发的)和完整的编译器命令行。 –
你用-std = C++ 11编译过吗? – 2017-07-30 16:17:54
我已更新最低代码。我没有与std = C++ 11编译,相同的标志为4.4.7 – Danny