根据 C++14 标准,下面的程序是病式的吗?
int f() { return 42; }
int main() {
(void)f();
}
如果不是,唯一的函数调用表达式是否包含在丢弃值表达式中? (注意是子表达式,不是整个表达式语句)
最佳答案
Is the following program ill-formed according to the C++14 standard?
没有。如果您有一些特定的理由认为这可能是无效的,您可能会得到更详细的答案,但是引用标准的每一句话以试图指出该句子不会使程序无效是没有生产力。
If not, is the sole function call expression contained within a discard-value expression?
唯一的函数调用表达式是丢弃值表达式。
5.2.9 Static cast [expr.static.cast]
6 Any expression can be explicitly converted to type cv
void
, in which case it becomes a discarded-value expression (Clause 5). [...]
我假设您已经知道 C 风格的转换会在可能的情况下执行 static_cast
。
关于c++ - C++14 中语句 (void)f() 的状态,它的格式是否错误?如果不是,f() 部分是丢弃值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33323932/