为什么 GCC 11.1 会警告 "use of possibly-NULL 'operator new(32)' where non-null expected"?
Why does GCC 11.1 warn about "use of possibly-NULL 'operator new(32)' where non-null expected"?
我正在使用 GCC 11.1,并且我已经使用选项 -fanalyzer
启用了静态分析器。现在在这一行中:
std::pair<NodeIterator, bool> result = idNodeMap.emplace(id,
new Node(id, point));
我收到以下警告:
..\src\Mesh\Mesh.cpp: In member function 'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)':
..\src\Mesh\Mesh.cpp:30:43: warning: use of possibly-NULL 'operator new(32)' where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]
30 | new Node(id, point));
| ^
'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)': events 1-2
|
|
In file included from ..\src\Mesh\Mesh.h:12,
from ..\src\Mesh\Mesh.cpp:9:
..\src\Mesh\Node.h:31:9: note: argument 'this' of 'Ct::Geometry::Node::Node(int, const gp_Pnt&)' must be non-null
31 | Node(int id, const gp_Pnt& point);
| ^~~~
我是否正确理解了警告,即 GCC 要我检查是否 new
returns null
?根据此 post: Will new return NULL in any case? 当前的编译器和声音编译选项绝不会出现这种情况。那么这是对罕见特殊情况的警告,我应该禁用它吗?
还是我忽略了什么,我的代码中存在真正的危险?
我正在使用 GCC 11.1,并且我已经使用选项 -fanalyzer
启用了静态分析器。现在在这一行中:
std::pair<NodeIterator, bool> result = idNodeMap.emplace(id,
new Node(id, point));
我收到以下警告:
..\src\Mesh\Mesh.cpp: In member function 'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)':
..\src\Mesh\Mesh.cpp:30:43: warning: use of possibly-NULL 'operator new(32)' where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]
30 | new Node(id, point));
| ^
'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)': events 1-2
|
|
In file included from ..\src\Mesh\Mesh.h:12,
from ..\src\Mesh\Mesh.cpp:9:
..\src\Mesh\Node.h:31:9: note: argument 'this' of 'Ct::Geometry::Node::Node(int, const gp_Pnt&)' must be non-null
31 | Node(int id, const gp_Pnt& point);
| ^~~~
我是否正确理解了警告,即 GCC 要我检查是否 new
returns null
?根据此 post: Will new return NULL in any case? 当前的编译器和声音编译选项绝不会出现这种情况。那么这是对罕见特殊情况的警告,我应该禁用它吗?
还是我忽略了什么,我的代码中存在真正的危险?