<div dir="ltr">Hi all,<div><br></div><div>I started exploring clang-tidy to create checks for a large C++ code base we have at work, with many developers with C background doing C++.</div><div><br></div><div>After doing the first tutorial on VirtualShadowingCheck, I wrote a check to detect paranoic code using pointers. By paranoic, I mean this:</div><div><br></div><div>static void foo(T* p, ...) {<br>    if (!p) return;<br>    // do something<br>}</div><div><br></div><div>The method is doing the right thing to check the input, but the interface itself could've been written with a reference, thus delegating to the caller the responsability of doing the null check.<br><br>This is not at all always possible, since this style can be valid for several reasons: pointers can refer diverse conceptual objects, e.g. arrays), the function could be virtual, thus forced to follow the same parameters, and so on.</div><div><br></div><div>But still, controversial as it is, I ran this check on LLVM code base.<br><br>llvm/tools/clang/lib/Sema/SemaLookup.cpp:3453 is one example. (the check finds over 15 violations, but I haven't analyzed them all)</div><div><br></div><div><div>This function is one example that could be ignoring a potential mistake. The caller could expect a valid pointer in at least some of those calls. The convenience of writing:</div><div><br></div><div>foo(something->getPointer(), ...);</div><div><br></div><div>can stimulate the developer to not write checks/assertions for some cases that he/she expects the pointer to be valid.</div><div><br></div><div>All that being said, I have some questions:</div><div><br></div><div>1 - Is the community receptive to such controversial checks? Or is clang-tidy only interested in low false positive/ non controversial checks?</div><div>2 - Any feedback on this specific check?</div><div>3 - Are there more check ideas waiting for someone to implement so I could pick up, learn more and actually contribute to the code base?</div><div><br></div><div><br></div><div>Thanks,</div><div>Breno Rodrigues Guimarães<br></div><div class="gmail_signature"><div><br></div><div><br></div><div><br></div></div>
</div></div>