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

Jian Cai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 11:22:25 PDT 2019


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


================
Comment at: clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp:49
+    diag(OperatorLoc, "POSIX functions (except posix_openpt) never return negative values")
+        << FixItHint::CreateReplacement(OperatorLoc, Twine(">").str());
+    return;
----------------
gribozavr wrote:
> Please add tests for fix-its.
The fix-it is triggered when cases like posix_*(...) < 0 are detected (except posix_openpt) , which are currently covered in the unit test. The test runtime will make sure fix-its are applied.


================
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:
> 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.


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