llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] readability-identifier-naming does not enforce `MemberCase` when `PrivateMemberSuffix` is enabled.

Open carlosgalvezp opened this issue 6 months ago • 6 comments

Example:

class Foo
{
 private:
    int Something_;
};

Running clang-tidy with:

-checks=readability-identifier-naming --config="{CheckOptions: {readability-identifier-naming.MemberCase: lower_case, readability-identifier-naming.PrivateMemberSuffix: '_'}}"

Gives no warnings even though the member should have lower_case. https://godbolt.org/z/PPr35KqjW

Removing the PrivateMemberSuffix option makes the warning show up as intended:

https://godbolt.org/z/Tdz5fT9fj

But these are orthogonal options so they should have no effect on each other.

carlosgalvezp avatar May 19 '26 09:05 carlosgalvezp

@llvm/issue-subscribers-clang-tidy

Author: Carlos Galvez (carlosgalvezp)

Example:
class Foo
{
 private:
    int Something_;
};

Running clang-tidy with:

-checks=readability-identifier-naming --config="{CheckOptions: {readability-identifier-naming.MemberCase: lower_case, readability-identifier-naming.PrivateMemberSuffix: '_'}}"

Gives no warnings even though the member should have lower_case. https://godbolt.org/z/PPr35KqjW

Removing the PrivateMemberSuffix option makes the warning show up as intended:

https://godbolt.org/z/Tdz5fT9fj

But these are orthogonal options so they should have no effect on each other.

Same issue for PrivateMemberPrefix: https://godbolt.org/z/8Y6aE6Td8

chrchr-github avatar May 19 '26 10:05 chrchr-github

hey can i work on this issue ??

AnkitDubeycs25 avatar May 19 '26 12:05 AnkitDubeycs25

@AnkitDubeycs25 Sure, just assigned you :)

carlosgalvezp avatar May 19 '26 18:05 carlosgalvezp

hey i am working on another thing and i am not getting time to solve this issue can you unassign ..

AnkitDubeycs25 avatar Jun 02 '26 08:06 AnkitDubeycs25

Hey, I might have the same, or at least a closely related issue. Example:

struct myStructure_t
{
};
--checks=readability-identifier-naming --config="{CheckOptions: {readability-identifier-naming.StructCase: camelBack, readability-identifier-naming.StructSuffix: '_c'}}"

clang-tidy tells me

warning: invalid case style for struct 'myStructure_t' [readability-identifier-naming]
   93 |   struct myStructure_t
      |          ^~~~~~~~~~~~~~~~~~~~~~~
      |          myStructure_t_c
   94 |   {
   95 |   };

We use different suffixes, mostly _c for classes and structs, and _t for types and a couple more things. I guess because clang-tidy just sees an _ in the class name, it assumes some form of snake case, assumes that to be wrong, and also suggests adding the correct suffix on top. Hence its suggestion myStructure_t_c, however its own suggestion doesn't pass both checks, does it? At least it looks like that any case has more precedence than some pure form like camelBack 🤔

Can this be overcome somehow with the current feature set of clang-tidy? If you think this is another issue and worth reporting separately, just say so. Thanks.

sebastianzander avatar Oct 21 '26 09:10 sebastianzander