关于在nullptr上调用delete的C ++ 17标准怎么说? [英] What C++17 standard say about calling delete on nullptr?

查看:1396
本文介绍了关于在nullptr上调用delete的C ++ 17标准怎么说?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++ 03标准语言:

C++03 Standard say's:

5.3.5删除

[...]在任一选择中,如果delete操作数的值为空指针,则该操作无效.[...]

[...] In either alternative, if the value of the operand of delete is the null pointer the operation has no effect.[...]

char *p = nullptr;
delete p; //no effect

这意味着在c ++中删除空指针是有效的.

It means, it is valid to delete null pointer in c++.

关于在nullptr指针上调用delete的C ++ 17标准怎么说?

What C++17 standard say about calling delete on nullptr pointer?

推荐答案

是的,它是有效的,并且会导致noop. 参考

Yes it is valid, and it results in a noop. reference

如果expression的计算结果为空指针值,则不会调用析构函数,也不会调用释放函数.

If expression evaluates to a null pointer value, no destructors are called, and the deallocation function is not called.

这篇关于关于在nullptr上调用delete的C ++ 17标准怎么说?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆