Enable most relevant clang-tidy checks and fix uncovered issues. (#220)

Most of these were fixed automatically (including things like adding
`[[nodiscard]]` and such). A number of others required manual edits.
I think all of them were pretty nice improvements.

There were a few places where the issues really stem from external
constraints and I've disabled the checks: GoogleTest macros or the
specific LibFuzzer entry points.

The only other places I disabled are the implicit conversions to
a private `enum` in the classes wrapping those `enum`s. These implicit
conversions are necessarily implicit to serve their only purpose:
enabling their use in `switch` statements and `case` labels. When these
were highlighted, it showed that one of these was actually converting to
an *`int`*. I've switched that to use the private `enum` instead as
doing so is important to enable warnings on non-covering `switch`
statements over than `enum`. And indeed, there is a `switch` that was
was implicitly relying on falling through in this way, so I've added the
explicit documentation of the intentional pattern to address that
warning.

Sorry this is so large, all of this somewhat fell out of enabling the
`clang-tidy` checks. If it is too difficult to review as lump, I can
work on breaking it apart as needed. Just let me know.
This commit is contained in:
Chandler Carruth
2020-12-08 14:43:37 -08:00
committed by GitHub
parent 2efbe1074e
commit d4a2d435b8
15 changed files with 155 additions and 97 deletions
+5 -2
View File
@@ -52,7 +52,7 @@ auto ParseTree::Parser::ConsumeIf(TokenKind kind)
auto ParseTree::Parser::AddLeafNode(ParseNodeKind kind,
TokenizedBuffer::Token token) -> Node {
Node n(tree.node_impls.size());
tree.node_impls.push_back(NodeImpl(kind, token, /*SubtreeSize=*/1));
tree.node_impls.push_back(NodeImpl(kind, token, /*subtree_size_arg=*/1));
return n;
}
@@ -94,7 +94,7 @@ auto ParseTree::Parser::AddNode(ParseNodeKind n_kind, TokenizedBuffer::Token t,
SubtreeStart& start, bool has_error) -> Node {
// The size of the subtree is the change in size from when we started this
// subtree to now, but including the node we're about to add.
int tree_stop_size = tree.node_impls.size() + 1;
int tree_stop_size = static_cast<int>(tree.node_impls.size()) + 1;
int subtree_size = tree_stop_size - start.tree_size;
Node n(tree.node_impls.size());
@@ -346,6 +346,9 @@ auto ParseTree::Parser::ParseDeclaration() -> llvm::Optional<Node> {
return ParseFunctionDeclaration();
case TokenKind::Semi():
return ParseEmptyDeclaration();
default:
// Errors are handled outside the switch.
break;
}
// We didn't recognize an introducer for a valid declaration.