gpt4 book ai didi

c++ - 为什么 GCC 可以编译 std::exception ("some error msg") 而不会出错?

转载 作者:行者123 更新时间:2023-11-28 04:14:01 25 4
gpt4 key购买 nike

我发现以下代码会抛出参数消息异常,但 GCC 可以成功编译它而不会出现任何错误。

当我用clang编译的时候,结果是失败。我想调试 GCC 编译过程以找出与 GCC 选项 -Q 的区别,但它似乎不起作用。希望有人能给我一些建议,或者告诉我为什么GCC可以编译成功。

T* lpItem = new T;
if (NULL == lpItem)
{
throw std::exception("New CachePool Item Fail");
}

最佳答案

GCC 正在利用 [member.functions]添加类似

的内容
std::exception::exception(const char *);

Clang 不是

For a non-virtual member function described in the C++ standard library, an implementation may declare a different set of member function signatures, provided that any call to the member function that would select an overload from the set of declarations described in this document behaves as if that overload were selected. [ Note: For instance, an implementation may add parameters with default values, or replace a member function with default arguments with two or more member functions with equivalent behavior, or add additional signatures for a member function name. — end note ]

添加了强调

关于c++ - 为什么 GCC 可以编译 std::exception ("some error msg") 而不会出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57050442/

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