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
- Repository
- rCTE Clang Tools Extra
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 ↗ | (On Diff #165792) | 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 ↗ | (On Diff #165841) |
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 ↗ | (On Diff #165792) | Ah, thank you for the explanation -- that makes sense. |