c++ - C++17 标准对 nullptr 调用 delete 有何规定?

标签 c++ language-lawyer c++17 delete-operator nullptr

C++03 标准说的是:

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++中删除空指针是有效的。

C++17 标准对 nullptr 指针调用 delete 有何规定?

最佳答案

是的,它是有效的,并且会导致空操作。 reference

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

关于c++ - C++17 标准对 nullptr 调用 delete 有何规定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47354881/

相关文章:

c++ - 通过可移动物体

opencv - 安卓 : linking to opencv results in SIGBUS (signal SIGBUS: illegal alignment) when exception is thrown

c++ - 函数返回值是否是自动对象并因此保证被破坏?

c++ -++x %= 10 在 C++ 中是否明确定义?

c++ - 实现类 std::variant 类时存储类型标记的问题

c++ - 你如何在 C++ 中实现协程

c++ - GLSL - 统一缓冲对象奇怪的行为

c++ - 按级别缩进的 pretty-print C++ 容器

c++ - 如何使用 blitz_0.9

c++ - 为什么双重否定会改变 C++ 概念的值(value)?