[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

Paul Fultz II via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 9 12:30:42 PST 2018

pfultz2 added a comment.

> I don't have a script for it. I've used "bear" with at least some of those projects because they use makefiles rather than cmake (https://github.com/rizsotto/Bear). I'm not tied to those projects specifically, either, so if you have a different corpus you'd prefer to use, that's fine. The important bit is testing it across a considerable amount of C code and C++ code to see whether this diagnostic is too chatty or not.

So I did a grep over these codebases(with `grep -E '\bsizeof\([^()"*]+\([^()]*\)'`). Most of them are macros which access elements(ie no function call) or are used in type traits. The only false positive I saw was here:


So I dont think it will be too chatty.

> That won't catch many (most?) of the issues demonstrated by PVS-Studio; the rule their check follows are to warn on side-effecting operations (which Clang already does with -Wunevaluated-expression) and arithmetic expressions in sizeof.

It finds function calls as well. I tried on MIOpen and it caught the errors like I mentioned earlier here:


  rCTE Clang Tools Extra


More information about the cfe-commits mailing list