[clang-tidy] multiple declaration statement check contribution

Hi,

I would like to know if there is any need for a readability check that checks for multiple declarations in one statement (init-declarator list). Things like this:

long int lint1, *lintptr1, lintaray10[10];

long int lint2 = 3, *lintptr2,
lintaray2[2] = { 1, 2 };

int int3 = f(), intarray[] = { 1, 2, 3, 4 };
const int cint3 = 4, cintarray[] = { 1, 2, 3, 4 };

may be transformed into:

long lint1;
long *lintptr1;
long lintaray10[10];

long lint2 = 3;
long *lintptr2;
long lintaray2[2] = { 1, 2 };

int int3 = f();
int intarray[4] = { 1, 2, 3, 4 };

const int cint3 = 4;
const int cintarray[4] = { 1, 2, 3, 4 };

Here is the full example with before (http://pastebin.com/raw/KnrzNWnM) and after (http://pastebin.com/raw/rLmPZRxP).

I haven’t worked for a long time on the code and like to continue, especially implement these suggested features (http://lists.llvm.org/pipermail/cfe-dev/2015-December/046556.html).

I am open for any hints or additional features.

Best,
Firat

Kirill Bobyrev is working on one.
See https://reviews.llvm.org/D25024

As far as I can see, the check does not include any FixItHint yet that I have already implemented for most of the cases. Kirill is it OK for you, if I keep continuing this and provide a patch?

Regarding differences between CERT and CppCore:
How about providing a general readability-checker that splits up any init-declarator list into single init-declarators? Then, we may provide “pseudo” cert-one-name-per-declaration and cppcore-one-name-per-declaration checks which will register the general readability checker and use Options to pass the config paramer (cert and cppcore) to the general check.

Something like:

// ReadabilityTidyModule.cpp

CheckFactories.registerCheck(“readability-one-name-per-declaration”);

// CERTTidyModule.cpp
CheckFactories.registerCheckreadability::OneNamePerDeclarationCheck(“cert-one-name-per-declaration”);

ClangTidyOptions getModuleOptions() override {
ClangTidyOptions Options;
auto &Opts = Options.CheckOptions;
Opts[“cert-one-name-per-declaration.style”] = “cert”;
return Options;
}

// CppCoreGuidelinesModule.cpp
CheckFactories.registerCheckreadability::OneNamePerDeclarationCheck(“cppcoreguidelines-one-name-per-declaration”);

ClangTidyOptions getModuleOptions() override {
ClangTidyOptions Options;
auto &Opts = Options.CheckOptions;
Opts[“cert-one-name-per-declaration.style”] = “ccpcore”;
return Options;
}

Any thoughts on this?

Hi Firat,

Sure, go ahead!

Unfortunately, I don’t have much time at the moment.

I would suggest to enhance CppCoreGuidelines rule too: I think it’s currently not restrictive and precise enough. I’ve opened an Issue [0] on Github; sadly, there’s no feedback yet.