我开始使用 clang 来替代 gcc。但是当我删除[]指针时,它会发出警告。但当我改变时,警告就消失了。为什么以及如何处理?
int *a = new int[1];
int *b = new int[1];
delete[] a, b;
a.cpp:7:17: warning: expression result unused [-Wunused-value]
delete[] a, b;
int *a = new int[1];
int *b = new int[1];
delete[] a;
delete[] b;
没有警告。
最佳答案
delete[] a, b;
解析为:
(delete[] a), (b);
您可以真正将其视为:
delete[] a;
b;
在这种情况下,很明显您没有对 b
做太多事情。
GCC 的警告在哪里?
如果您使用 -Wall
,gcc 至少自 2007 年起也会对此发出警告(gcc 4.1.2):
<source>: In function 'int main()':
<source>:4:18: warning: right operand of comma operator has no effect [-Wunused-value]
4 | delete[] a, b;
| ^
Compiler returned: 0
关于c++ - 关于删除指针的 Clang 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73904787/