[PATCH] D42682: [clang-tidy] Add io-functions-misused checker

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 6 10:22:04 PST 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/bugprone/IoFunctionsCheck.cpp:32
+                has(cxxMemberCallExpr(
+                    on(hasType(namedDecl(hasAnyName("istream")))),
+                    callee(cxxMethodDecl(hasName("get")).bind("DeclOfGet"))))),
----------------
`::std::istream`


================
Comment at: clang-tidy/bugprone/IoFunctionsCheck.cpp:47-49
+      "consider to cast the return value of %0 from type integer to type char, "
+      "possible loss of precision if an error has occurred or the end "
+      "of file has been reached");
----------------
This diagnostic confuses me, so perhaps you can explain the situation you want to diagnose a bit further.

FIO34-C is about situations where `sizeof(char) == sizeof(int)` and the call returns EOF/WEOF. In that case, there's no way to distinguish between an EOF/error and a valid character. Suggesting to explicitly cast to a character type doesn't add any safety to the code -- the user needs to insert calls to `feof()` or `ferror()` instead (to make it portable, anyway) and should store the character value in a sufficiently large integer type before doing the comparison against EOF.

Are you trying to catch a different kind of bug?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D42682





More information about the cfe-commits mailing list