加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Xcode / LLVM catch子句与派生类型不匹配

发布时间:2020-12-14 19:13:46 所属栏目:百科 来源:网络整理
导读:在 gcc 4.2中,这有效: #include stdexcept#include iostreamint main() { try { throw std::runtime_error("abc"); } catch (const std::exception ex) { std::cout ex.what(); }} 在Xcode 4.3.2(带有LLVM 3.1的iOS,-std = c 11)中,这会因为终止而失败,称为
在 gcc 4.2中,这有效:

#include <stdexcept>
#include <iostream>

int main() {
    try {
        throw std::runtime_error("abc");
    } catch (const std::exception& ex) {
        std::cout << ex.what();
    }
}

在Xcode 4.3.2(带有LLVM 3.1的iOS,-std = c 11)中,这会因为终止而失败,称为抛出异常,从未到达NSLog(…)行:

#include <stdexcept>

int main() {
    try {
        throw std::runtime_error("abc");
    } catch (const std::exception& ex) {
        NSLog(@"%s",ex.what());
    }

    return UIApplicationMain(argc,argv,nil,nil);
}

但这有效:

#include <stdexcept>

int main() {
    try {
        throw std::runtime_error("abc");
    } catch (const std::runtime_error& ex) {
        NSLog(@"%s",nil);
}

是什么赋予了?

解决方法

gcc是正确的:

15.3p3 A handler is a match for an exception object of type E if

  • … or
  • the handler is of type cv T or cv T& and T is an unambiguous public base class of E,or

这听起来像是一个xcode bug(而且是一个令人惊讶的基本错误!)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读