[clang-tools-extra] [clang-tidy][readability-named-parameter] Add an option to print names without comment (PR #147953)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 10 09:03:10 PDT 2025
================
@@ -105,12 +117,26 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
NewName = Name;
}
- // Now insert the comment. Note that getLocation() points to the place
+ // Now insert the fix. Note that getLocation() points to the place
// where the name would be, this allows us to also get complex cases like
// function pointers right.
const ParmVarDecl *Parm = P.first->getParamDecl(P.second);
- D << FixItHint::CreateInsertion(Parm->getLocation(),
- " /*" + NewName.str() + "*/");
+
+ // The fix depends on the InsertPlainNamesInForwardDecls option,
+ // whether this is a forward declaration and whether the parameter has
+ // a real name.
+ const bool IsForwardDeclaration = (!Definition || Function != Definition);
+ if (InsertPlainNamesInForwardDecls && IsForwardDeclaration &&
+ NewName != FallbackName) {
+ // For forward declarations with InsertPlainNamesInForwardDecls enabled,
+ // insert the parameter name without comments
+ D << FixItHint::CreateInsertion(Parm->getLocation(),
+ " " + NewName.str());
+ } else {
+ // Default behavior: insert the parameter name as a comment
----------------
vbvictor wrote:
nit: Maybe this comment is not need, we get from context that it is default behavoir
https://github.com/llvm/llvm-project/pull/147953
More information about the cfe-commits
mailing list