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

标签 c++

我发现以下代码会抛出参数消息异常,但 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/

相关文章:

c++ - 可以使用 C++14 索引序列改进元组可变参数模板递归吗?

c++ - 在 openframeworks 中使用 c++ vector 的生命元胞自动机游戏

c++ - 一种在 C++ 中读取二进制文件的 Kosher 方法

c++ - 返回类型模板(enable_if)禁止什么?

c++ - 优雅地从指针初始化 std::array 到缓冲区?

c++ - Gtk::Window 在将我的 gtkmm2 移植到 gtkmm3 应用程序时显示并退出

c++ - 这个递归方法不应该一到return就结束了吗?

c++ - 使用 nBufferMax 等于 0 的 LoadString

c++ - 具有政策的 Alexandrescu 单例

c++ - 将文件流从 C++ dll 返回到 Centura Team Developer