This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Refactor HeaderGuardCheck to add HeaderGuardStyle
Needs ReviewPublic

Authored by KyleFromKitware on Jan 26 2023, 2:46 PM.

Details

Reviewers
sscalpone
njames93
aaron.ballman
hokein
gribozavr2
carlosgalvezp
Group Reviewers
Restricted Project
Summary

Having more than one check for header guards can potentially lead
to a conflict where different header guard checks suggest different
corrections. Refactor into a single HeaderGuardCheck that can
create one of multiple HeaderGuardStyle instances from a registry.
Refactor LLVMHeaderGuardCheck to extend this class.

Diff Detail

Event Timeline

Herald added a reviewer: njames93. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
KyleFromKitware requested review of this revision.Jan 26 2023, 2:46 PM
KyleFromKitware changed the edit policy from "All Users" to "KyleFromKitware (Kyle Edwards)".

Note: I do not have possibility to add code comments - is there some too strict permissions set for this patch? It has not happened to other patches.

Review comment:

I think the design choice in clang-tidy is that checks from different modules should not depend on each other like this, that's why a common utils folder exists.
What is the difference between llvm-header-guard and readability-header-guard? Could one be the alias of the other, possibly with some added configuration options?

Also, in general the design choice is that checks should be independent and authors should not need to care about whether they conflict with other checks. In this particular case, if both checks are providing different results, users should choose one and disable the other. Header guard style is a purely stylistic matter, so it's no surprise different checks will lead to different results.

KyleFromKitware changed the edit policy from "KyleFromKitware (Kyle Edwards)" to "All Users".Jan 27 2023, 8:52 AM

Note: I do not have possibility to add code comments - is there some too strict permissions set for this patch? It has not happened to other patches.

I accidentally set the permissions too strict, I've fixed it here and on all my other diffs.

I think the design choice in clang-tidy is that checks from different modules should not depend on each other like this, that's why a common utils folder exists.
What is the difference between llvm-header-guard and readability-header-guard? Could one be the alias of the other, possibly with some added configuration options?

See the discussion in D142123. We decided it would be best to have a single readability-header-guard which can select one of several different styles. llvm-header-guard temporarily exists as a deprecated alias to readability-header-guard with the llvm style selected, and will be removed in a future version.

Added virtual destructor to HeaderGuardStyle.

clang-tools-extra/clang-tidy/utils/HeaderGuard.h