This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] modified identifier naming case to use CT_AnyCase for ignoring case style
ClosedPublic

Authored by jutocz on Mar 14 2017, 4:11 AM.

Details

Summary

Using CaseType::CT_AnyCase for selected identifier results in inheriting case style setting from more basic identifier type.

This patch changes CT_AnyCase behavior to ignore case style of specified identifier. If case style was not set, llvm::Optional will be used for keeping this information (llvm::Optional<>::hasVal), thus CT_AnyCase will no longer mean more general identifier style should be used.

This eliminates false-positives when naming convention is not clear for specific areas of code (legacy, third party) or for selected types.

Diff Detail

Event Timeline

jutocz created this revision.Mar 14 2017, 4:11 AM
alexfh edited edge metadata.Mar 14 2017, 9:46 AM

I understand your use case, but this patch makes the check's behavior more confusing: having both "any case" and "ignore case" with subtle differences in behavior seems very misleading. The problem seems to be coming from the usage of CT_AnyCase to denote uninitialized style. Should we just remove NamingStyle::isSet and use llvm::Optional<NamingStyle> instead of NamingStyle where appropriate?

alexfh edited reviewers, added: berenm; removed: rsmith.Mar 14 2017, 9:47 AM
alexfh added a subscriber: cfe-commits.

BTW, next time please add cfe-commits to subscribers when you create the patch to get it sent properly to the mailing list.

berenm edited edge metadata.Mar 14 2017, 9:52 AM

I understand your use case, but this patch makes the check's behavior more confusing: having both "any case" and "ignore case" with subtle differences in behavior seems very misleading. The problem seems to be coming from the usage of CT_AnyCase to denote uninitialized style. Should we just remove NamingStyle::isSet and use llvm::Optional<NamingStyle> instead of NamingStyle where appropriate?

I agree

You are right, it does look misleading. I'll try to modify it the way you suggest (though I'm new to LLVM, so be ready to give me more comments;).

You are right, it does look misleading. I'll try to modify it the way you suggest (though I'm new to LLVM, so be ready to give me more comments;)

Sure, thank you for the work!

alexfh requested changes to this revision.Mar 16 2017, 7:13 AM
This revision now requires changes to proceed.Mar 16 2017, 7:13 AM
jutocz updated this revision to Diff 92108.Mar 17 2017, 2:46 AM
jutocz edited edge metadata.
jutocz retitled this revision from [clang-tidy] added new identifier naming case type for ignoring case style to [clang-tidy] modified identifier naming case to use CT_AnyCase for ignoring case style.
jutocz edited the summary of this revision. (Show Details)

I've modified patch to use llvm::Optional for not defined naming style and naming case.
I had to use llvm::Optional in two places:

  • for entries in collection of naming styles (IdentifierNamingCheck::NamingStyles) where style for specific identifier was not set (more general style will be used in this case)
  • for case type in NamingStyle, where case style was not set but prefix or postfix was (this remains a bit unintuitive, bacause case style will be ignored and only prefix or postfix will get validated)
jutocz updated this revision to Diff 92205.Mar 17 2017, 2:17 PM

Updated diff to show full context

alexfh accepted this revision.Mar 22 2017, 3:11 AM

A couple of nits, otherwise looks good. Do you need me to commit the patch for you?

clang-tidy/readability/IdentifierNamingCheck.cpp
169

llvm::None is more idiomatic.

184

llvm::None here as well.

212

.hasValue() can be omitted, since llvm::Optional<> defines operator bool and operator *, and thus can be used in a similar fashion as a pointer / smart pointer: if (opt) DoSomething(*opt);.

This revision is now accepted and ready to land.Mar 22 2017, 3:11 AM
jutocz updated this revision to Diff 92619.EditedMar 22 2017, 5:15 AM

I like the idea of using llvm::None plus operator bool and operator *.
I've updated the diff to use llvm::Optional this way .

And yes, I need your help in committing the patch. Thanks.

This revision was automatically updated to reflect the committed changes.