[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

Bhuminjay Soni via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 10 04:18:42 PST 2024


11happy wrote:

> I'm not fan about this check. For me there is no use case for it. For sure it's not readability, simply because explicit return is more readable, and people who do not know that main by default will return 0 may even consider this check a bug, as why all functions got return but not this. Other issue is that many projects enable all readability checks, and as this one is controversial and not common it shouldn't be under readability, more like misc. There are many things that aren't needed, for example compiler is able to generate destructor, but still rule of 3/5 require it in some cases to be done explicitly, same is with return 0, there could be easily a check that could enforce explicit return in all functions, and that would also be readability.
> 
> As for the check:
> 
> * wrong name
> * wrong category, it should be more a 'misc' for me
> * in current form it will catch also 'return 1';
>   I would say that if this check had to exists (i still cannot find use case for it), then it should be configurable to enforce 'return 0' or enforce lack of 'return 0'. And left configured to an most safe/common approach. What if someone wanted to do 'return 1', but forget to put return, and compiler didn't warn.

Sure I will Look into these and will update it accordingly. I added it into readability category as It was mentioned by author on the issue #61957 , also can you please suggest the name that would be more suitable.

> The check could be placed under readability-* category.

As a new contributor to LLVM, I am willing to take to your guidance and suggestions.
Thank you

https://github.com/llvm/llvm-project/pull/77586


More information about the cfe-commits mailing list