gpt4 book ai didi

c++ - 升级到 G++ 4.8 - exception_ptr.h 不支持异常传播

转载 作者:搜寻专家 更新时间:2023-10-31 02:10:21 26 4
gpt4 key购买 nike

我正在尝试使用 g++ 4.8 重新编译一个巨大的遗留应用程序,以便调试 glibc 检测到的内存损坏 问题(使用 AddressSanitizer)。之前我们使用的是 g++ 4.4.7。

但是,编译失败:

/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.

编辑二

跟踪包含文件归结为 __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++ 版本:

$ g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)

编辑二

我已经在 Centos 7 VM 上运行的 g++ 6.3.1 上进行了尝试。还是一样的问题。

源文件 - 仅一行

#include <bits/exception_ptr.h>

编译命令:g++ -c -o test.o test.cpp

最佳答案

首先包括<bits/exception_ptr.h>直接在技术上不受支持。它在头文件中是这么说的。这或多或少是偶然在 GCC 4.4 中起作用的。这个头文件的 C++11 迁移破坏了它,因为命名空间的原因,C++98 代码不能使用 ATOMIC_INT_LOCK_FREE宏,标题不再起作用。

在 GCC 7 中,这已作为此错误的一部分修复(再次意外):

包含 <bits/exception_ptr.h> 的技巧直接应该在这个版本中再次工作。

这意味着您的选择是:

  1. 在 C++11 或更高版本的模式下编译您的代码(推荐使用 C++14 和 GCC 6)。
  2. 当 GCC 7 可用时升级到 DTS 7,它具有重新启用 C++98 hack 的上游修复程序。
  3. 包装使用std::exception_ptr在不透明类型中,在 C++11 或更高版本的模式下编译其实现,并将系统的其余部分保持在 C++98 模式。
  4. 使用另一种 hack,比如这个:

    #include <exception>
    #ifndef ATOMIC_INT_LOCK_FREE
    # define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
    #endif
    #include <bits/exception_ptr.h>

    同样,这完全不受支持,但它应该不会比您今天拥有的(使用 GCC 4.4)差多少。

关于c++ - 升级到 G++ 4.8 - exception_ptr.h 不支持异常传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45400971/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com