[PATCH] D63623: [clang-tidy] new check: bugprone-posix-return

Jian Cai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 15:05:20 PDT 2019


jcai19 marked 2 inline comments as done.
jcai19 added inline comments.


================
Comment at: clang-tools-extra/test/clang-tidy/bugprone-posix-return.cpp:96
+  if (posix_fadvise(0, 0, 0, 0) < 0) {}
+  if (posix_fadvise(0, 0, 0, 0) >= 0) {} else {}
+  if (posix_fadvise(0, 0, 0, 0) == -1) {}
----------------
gribozavr wrote:
> jcai19 wrote:
> > gribozavr wrote:
> > > Shouldn't there be a warning in the else branch?
> > This check only matches calls to the POSIX functions in the global scope, not member functions or functions defined within namespaces. Although in the global scope,  this particular case will still pass as there won't be a ``<`` binary operator for the else branch so no matching will happen.
> Sorry, yes, that's what I meant -- if we warn on `< 0`, then we should warn on the else branch of `>=`. I just commented on the wrong test -- sorry about that.
Thanks for the clarification. Actually >= 0 is always true since the call return 0 on success and a positive value on error, so the else branch will never be reached. I have update my check and the warning message to reflect this. Good catch!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63623/new/

https://reviews.llvm.org/D63623





More information about the cfe-commits mailing list