gpt4 book ai didi

c++ - "Return value optimization"会导致未定义的行为吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:57:13 25 4
gpt4 key购买 nike

阅读 this一位回复者指出的维基百科文章针对以下问题:

C++ Copy constructor, temporaries and copy semantics

我遇到了这条线

Depending on the compiler, and the compiler's settings, the resulting program may display any of the following outputs:

这不符合未定义行为的条件吗?我知道这篇文章说 Depending on the compiler and settings 但我只想清除它。

最佳答案

不,这不是未定义的行为。未定义的行为在标准中有一个特定的定义(主要是:“行为,例如在使用错误的程序构造或错误的数据时可能出现的行为,本国际标准对此没有强加任何要求。”)在这种情况下,行为是未指定的,但不是未定义的。

不同之处在于,任何具有未定义行为的任​​何执行都会使程序的所有行为都未定义(即任何事情都可能发生)。对于这种特殊的未指定行为,只会发生以下两种情况之一:复制构造函数执行或不执行。

关于c++ - "Return value optimization"会导致未定义的行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2323940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com