jyknight wrote:

I note that this commit (probably unintentionally) fixed an issue with the 
`-Wnonnull` warning for return values in Objective-C++ code.

Previously, `id _Nonnull foo() { return nullptr; }` does not warn under `clang 
-fobjc-arc -target x86_64-apple-macos11 -x objective-c++ -fsyntax-only`. It did 
warn with `-fno-objc-arc`, however. Now, it does warn in both cases. This seems 
like an improvement -- but the state of things is still pretty weird.

But, that only started working with `return nullptr`, not with `return 0`, 
though I'd expect those to be treated the same way. It also didn't start 
working for `-x objective-c` mode with a `return (void*)0;`.

(https://godbolt.org/z/1voxqhKbE)

I'd also have expected that this change in behavior would have required test 
changes to the objc nullability tests, but it didn't, because mostly tests 
don't enable `-fobjc-arc`. The test case `returnsNilObjCInstanceDirectly` in 
`clang/test/Analysis/nullability_nullonly.mm` does seem like it'd notice the 
change in behavior, but it has defined `nil` as `0`, not `nullptr`. (Also, 
that's primarily a test for Clang Static Analyzer's nullability checker, not 
Sema's nullability warning. The same function in 
`clang/test/Analysis/nullability-no-arc.mm` does see the Sema -Wnonnull warning 
too, however.)

Anyways, I don't think it's _bad_ that this commit has had this particular 
effect, but it's weird, and I wonder if this weirdness might affect other 
situations than ObjC ARC types, too.

https://github.com/llvm/llvm-project/pull/82705
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to