[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 22 08:22:02 PST 2020


njames93 marked an inline comment as done.
njames93 added a comment.

In D73098#1833736 <https://reviews.llvm.org/D73098#1833736>, @aaron.ballman wrote:

> In D73098#1832489 <https://reviews.llvm.org/D73098#1832489>, @njames93 wrote:
>
> > In D73098#1832131 <https://reviews.llvm.org/D73098#1832131>, @Mordante wrote:
> >
> > > Would it make sense to also allow wmain with wchar_t? https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=vs-2019
> >
> >
> > Does wmain get used in a lot of projects. If it's very niche then I don't feel it warrants a place in here. If it does I'll add it in.
>
>
> It's not uncommon on Windows, at the very least. I think it's worth supporting.


I'll add that in



================
Comment at: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:474
   if (const auto *Decl = dyn_cast<ParmVarDecl>(D)) {
+    if (isParamInMainLikeFunction(*Decl))
+      return SK_Invalid;
----------------
aaron.ballman wrote:
> njames93 wrote:
> > aaron.ballman wrote:
> > > I think a better approach may be to look at the `DeclContext` for the `ParmVarDecl` object to see if it is a `FunctionDecl`, and if it is, call `FunctionDecl::isMain()` to check.
> > I specifically didn't want to do that as is I want to get functions that act like main, usually the case when main itself dispatches to other functions with the same signature. 
> I'm not certain that's a case we should support -- users who write their own main-like interfaces should probably follow their usual naming rules (even if we don't do it ourselves). For instance, this will catch functions that are definitely *not* `main`-like  except in the signature. e.g., `int accumulate_string_lengths(int count, char *strings[]);`
Thats a good point, how about checking if the name of the function starts or ends with "main" or "wmain" for windows, maybe even have an option to enable ignore "main like" functions, but always ignore the actual main function


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098





More information about the cfe-commits mailing list