<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57546>57546</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[-Wnullable-to-nonnull-conversion] is weak and dumb
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
alejandro-colomar
</td>
</tr>
</table>
<pre>
I was trying the feature, but it is trivial to silence warnings, and it also warns in some cases where it shouldn't:
```c
$ cat nonnull.c
int *_Nonnull f1(int *_Nullable p)
{
return p; // We got a warning :)
}
int *_Nonnull f2(int *_Nullable p)
{
int *_Null_unspecified q;
q = p; // Expected a warning, but not :/
return q; // Expected a warning, but not :/
}
int f3(int *_Nullable p)
{
return *p; // Expected a warning, but not :/
}
int *_Nonnull f4(int *_Nullable p, int *_Nonnull q)
{
if (p)
return p; // Should not get a warning here :(
return q;
}
```
```sh
$ clang nonnull.c -Weverything -Wno-nullability-extension -Wno-missing-prototypes -S -o /dev/null
nonnull.c:3:9: warning: implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull' [-Wnullable-to-nonnull-conversion]
return p; // We got a warning :)
^
nonnull.c:23:10: warning: implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull' [-Wnullable-to-nonnull-conversion]
return p; // Should not get a warning here :(
^
2 warnings generated.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVVclyozAQ_Rq4qHCBhBcOHLK5ai5zySHHKQGNUUZItiTs-O-nhfGGk5kkt6EwRlIv7z11o0JX-_wH2XFLnNkLtSKuAVIDd52BgD6QonNE4O3XxVZwSZwmVkhQJaCbUehjvSFXlTfk0up-3hKhiNUtkJJbsGTXgAFvYRvdyUoFdO4CdhfEj0F8fM7iw10OY5qisyNKK9VJOSnJYV4oRwJ69-vnYZ7USUAXp0mc4YUEsg5oNsSZ3x_TZAaQmcJFdk_Qfok3eQGy0gj9yId4XGfnx0uMN7np53Nfmv3qlF1DKWoBFdkgmish4myDIB6vYT69oYND8xPQ4wYpRN9jXo6iDGw33wxzS71mX5YaLb9L4x_Spx9geSBj0837-1Gj0eICfJx9UCHPfc32AFdwWSl9UfeYF--JPuZxLPDR0DYXBS85xj2XfPQCWzB71_h00YvSkeqpCincPoI3B8oKrQ5LrbAW7aK10U67_Rr7LnomkfY8Ktji0zsfkp1SIHyGvwx_px3BV9GupSixYUutEEGfpDa6JeoktUadwWDw-SA4Oe0DzvkvBSaJbuw9sGunAxTvE0zvkcngETlke1iLziiC6SAnGa4v9zS5voLp060k1GuSxP-tKH8T5_PlPI42VoyezgCMpMBwbOzJqLpDyJPZjFKWzrIsrHJWZSzjoRNOQv45av782QH_3Z8yVdcWYWdk3ji3tsMHgy5XwjVdMSl1iwMpt8c_3wyv-MXBIXZHB3haLafzaToLmxxowYuMFvMqS1mdlHQxZ3EJbEELNmUJDREWSOtRBpQq2JE-BL4jqFDkNKY0zmKWZNOELSY1LVmcVFCm6aKM-TxIY2i5kBOPY6LNKjR5D6no8NBMYymss-dFjs27UtCL4uPzzjXa5FzCK_I2GjWRuuUm7EHkPYk_dINWxw">