[cfe-dev] Nullable const pointer (-Wnullable-to-nonnull-conversion).
Alfred Zien via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 29 08:07:21 PST 2016
Hi!
There is strange behaviour of nullable const pointer.
Lets say I have function f.
int f(int* _Nonnull i) {
return *i;
}
And code like this:
int main() {
int* _Nullable p = 0;
return f(p);
}
produces error as expected, if I pass -Wnullable-to-nonnull-conversion
$ clang t.c -Werror -Wnullable-to-nonnull-conversion
t.c:7:12: error: implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull' [-Werror,-Wnullable-to-nonnull-conversion]
return f(p);
^
1 error generated.
But, if I change code like so
int main() {
int* _Nullable const p = 0;
return f(p);
}
compiler does not produces any errors.
It looks very strange.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161229/93e9e41d/attachment.html>
More information about the cfe-dev
mailing list