To summarize the request, you want a configuration for the clang-tidy
check called readability-identifier-naming that will require the use of uppercase letters for parameters of type const int &
and const int
but not int
.
In the current release of Clang+LLVM, 16.0.6, this is not possible. The ParameterCase
option applies to all three, while the ConstantParameterCase
option only applies to const int
, not const int &
, since the latter is a reference to a const
-qualified type, but is not const
-qualified itself (reference types cannot be const
-qualified).
There is no more specific option that applies to a const int &
parameter than ParameterCase
, as can be seen from the source code of IdentifierNamingCheck::findStyleKind
, excerpted below:
- Parameters are always
ParmVarDecl
AST objects.
- It (
const int &
) is neither constexpr
nor const
.
- It is not a parameter pack.
- It is not
Type
::isAnyPointerType()
, as that is true of
C/C++ pointers and Objective-C pointers, but not references.
- Thus only remaining applicable style is simply
SK_Parameter
,
which corresponds to the ParameterCase
option (for letter case
rules).
This could of course change in a future version if your Issue #64220 is acted upon. You might want to clarify in that issue that you (now) understand it is not possible in the current version, and you are making an enhancement request.
Source code excerpt:
StyleKind IdentifierNamingCheck::findStyleKind(
const NamedDecl *D,
ArrayRef<std::optional<IdentifierNamingCheck::NamingStyle>> NamingStyles,
bool IgnoreMainLikeFunctions) const {
...
if (const auto *Decl = dyn_cast<ParmVarDecl>(D)) {
if (isParamInMainLikeFunction(*Decl, IgnoreMainLikeFunctions))
return SK_Invalid;
QualType Type = Decl->getType();
if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
return SK_ConstexprVariable;
if (!Type.isNull() && Type.isConstQualified()) {
if (Type.getTypePtr()->isAnyPointerType() &&
NamingStyles[SK_ConstantPointerParameter])
return SK_ConstantPointerParameter;
if (NamingStyles[SK_ConstantParameter])
return SK_ConstantParameter;
if (NamingStyles[SK_Constant])
return SK_Constant;
}
if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
return SK_ParameterPack;
if (!Type.isNull() && Type.getTypePtr()->isAnyPointerType() &&
NamingStyles[SK_PointerParameter])
return SK_PointerParameter;
if (NamingStyles[SK_Parameter])
return SK_Parameter;
return SK_Invalid;
}
...