findStyleKind is only called if D is an explicit identifier with a name,
so the checks for operators will never return true. The explicit assert()
enforces this invariant.
Details
Diff Detail
- Build Status
Buildable 22729 Build 22729: arc lint + arc unit
Event Timeline
Is the condition for this assertion checked beforehand or could this create runtime failures?
It's checked by the (only) caller of the function on line 791:
if (const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl")) {
if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit())
return;
...
StyleKind SK = findStyleKind(Decl, NamingStyles);
if (SK == SK_Invalid)
return;
...
}| clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
|---|---|---|
| 551–552 | D51808 changes signature of isUsualDeallocationFunction(), which made me update the code here, which lead to @rsmith suggesting that this change is redundant and could use cleaning up, which led to this change. Any Decl which would return true for isUsualDeallocationFunction() or for is*Operator(), will always return nullptr for getIdentifier() because D->getName().isIdentifier() would be false. Speaking of which, the result of getIdentifier() is never used, so the check should probably be D->isIdentifier() both in this function and in the caller. | |
| clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
|---|---|---|
| 388 |
Scratch that. It's not worth the trouble, IMO. D->getDeclName().isIdentifier() is more verbose and does not buy us anything compared to D->getIdentifier() which expresses the intent well enough. | |
LGTM!
| clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
|---|---|---|
| 551–552 | Ah, thank you for the explanation -- that makes sense. | |
Can you also assert D is nonnull here? (isa<> used to take care of that, so it's a minor regression in checking.)