Does an expression with undefined behaviour that is never actually executed make a program erroneous?

前端 未结 9 974
情歌与酒
情歌与酒 2020-12-31 02:05

In many discussions about undefined behavior (UB), the point of view has been put forward that in the mere presence in a program of any construct that has UB in a p

9条回答
  •  我在风中等你
    2020-12-31 02:49

    No. Example:

    struct T {
        void f() { }
    };
    int main() {
        T *t = nullptr;
        if (t) {
            t->f(); // UB if t == nullptr but since the code tested against that
        }
    }
    

提交回复
热议问题