【问题标题】:Exception Specifications on VS2012VS2012 异常规范
【发布时间】:2013-09-15 19:12:54
【问题描述】:

我最近更新到 Visual Studio 2012,但在异常规范方面遇到了一些问题。 我不断收到具有表单的系统文件的错误

<some type> function(<some input>) _NOEXCEPT    
{
  <some code>
}

在哪里

 #define _NOEXCEPT  throw()

我不太明白为什么会出现错误,因为宏是定义的并且用途是由Visual Studio Exception Handling 定义的。错误类似于:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\list(1119): error C2059: syntax error : '{'
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\list(1119): error C2334: unexpected token(s) preceding '{'; skipping apparent function body

上面“列表”文件的第 1118-1121 行是:

const_iterator begin() const _NOEXCEPT
    {   // return iterator for beginning of nonmutable sequence
    return (const_iterator(this->_Nextnode(this->_Myhead), this));
    }

错误来自“list”和“xtree”,它们都位于上述路径中。 我已经尝试更改上面链接中指定的“\EH”标志,但这没有帮助。

关于什么可能导致这种情况的任何想法?

编辑:添加预处理器文件摘录。

const_iterator begin() const {printf("ERROR: %s\n     in file %s at line %d\n", ,"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\list",1118); throw(1);}
    {   
    return (const_iterator(this->_Nextnode(this->_Myhead), this));
    }

不确定我应该从这个文件中得到什么,但这里是示例代码。

【问题讨论】:

  • Use C/C++, Preprocessor, Generate Preprocessed File = Yes 看看真正变成了什么。
  • 您好,感谢您的回复,我继续创建了预处理器文件。我粘贴了一段我认为会产生错误的代码。我不确定,因为我不知道我在寻找什么。你能告诉我更多吗?
  • 嗯,这看起来不像throw(),是吗?您需要找到能够影响 _NOEXCEPT 宏的#define。右键单击它,转到定义。
  • 转到定义:#define _NOEXCEPT throw () 在其他文件中。我以为大括号的最后一部分没问题,throw() 变成了throw(1)

标签: c++ debugging visual-studio-2012 exception-handling


【解决方案1】:

编辑

事实证明,有一个带有宏的全局标题

#define throw(message) {printf("ERROR: %s\n in file %s at line %d\n", message,__FILE__,__LINE__); throw(1);}

这是导致所有问题的原因。取消定义宏会使事情顺利进行。


我放弃了尝试解决这个问题... 作为一种解决方法,我将 _NOEXCEPT 宏重新定义为不使用 throw,即

#define _NOEXCEPT  

在导致问题的头文件中。

我认为这不会是一个大问题,因为所有编译器都会忽略异常规范并且在 c++11 中已弃用

【讨论】:

  • 从历史上看,VS 编译器没有忽略空异常规范throw()。它确实影响了代码生成。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-14
  • 2018-10-30
  • 1970-01-01
  • 2017-10-08
  • 2012-03-14
  • 2013-12-16
  • 1970-01-01
相关资源
最近更新 更多