C++中的Throw和三元运算符

fmo*_*ncy 8 c++ operators ternary-operator

以下代码使用G ++ 4.6.1编译,但不适用于Visual Studio 2008

return (m_something == 0) ? 
    throw std::logic_error("Something wrong happened") : m_something;
Run Code Online (Sandbox Code Playgroud)

事实是Visual Studio编译器执行内部崩溃.

我想知道这是标准C++以及为什么它不能用Visual Studio编译,而是用G ++编译?

Joh*_*all 12

它是标准的C++.条件表达式中的then/else表达式中的任何一个(或两个)都允许是throw-expression(C++ 98 5.16/2).

如果Visual Studio在编译时崩溃了......这似乎是不幸的!