[cfe-dev] clang-tidy readability-identifier-naming check does not handle member usages correctly

Michael Jabbour via cfe-dev cfe-dev at lists.llvm.org
Sun Jul 22 12:32:44 PDT 2018


I am trying to refactor a code base to follow some naming conventions
using clang-tidy readability-identifier-naming check. Unfortunately, I
always get code that does not compile. The check does not seem to rename
any method calls and member variable usages. I found a question on
stackoverflow ( https://stackoverflow.com/q/50906481/2666212 ) that
talks about the same issue (but no answers).

I am posting the same reproducible example here:

.clang-tidy file:

Checks: '-*,readability-identifier-naming'
CheckOptions:
  - { key: readability-identifier-naming.ClassCase,             value:
CamelCase  }
  - { key: readability-identifier-naming.VariableCase,          value:
lower_case }
  - { key: readability-identifier-naming.FunctionCase,          value:
lower_case }
  - { key: readability-identifier-naming.MemberPrefix,          value:
m_         }
  - { key: readability-identifier-naming.ParameterCase,         value:
lower_case }

The configuration above makes functions in lower_case.

test.cpp file:

class one_class
{
public:
    int OneMethod(int OneArgument); //changes to one_method(int
one_argument)

    int OneAttribute;
};

int one_class::OneMethod(int OneArgument) //same change
{
    OneAttribute = 42;
    return OneArgument + 1;
}

int main(void)
{
    int OneVariable = 0;

    one_class c;
    OneVariable = c.OneMethod(OneVariable); //does NOT change!!
    c.OneAttribute = 21; //does NOT change!!

    return 0;
}

command:

$ clang-tidy -fix test.cpp --

I tried using various versions of clang (e.g. clang-3.8, clang-6, and
the development clang-7) and got the same result.

After skimming the check's source code, It seems like the check is
looking for DeclRefExprs to identify usages, but it never looks for
MemberExprs. Is this a bug? Are there any viable alternatives to this
check to do massive refactoring related to naming conventions?

Thanks,

Mike




More information about the cfe-dev mailing list