mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 07:11:04 +01:00
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:
@@ -27,8 +27,10 @@ class ParseNodeKind {
|
||||
public:
|
||||
// The formatting for this macro is weird due to a `clang-format` bug. See
|
||||
// https://bugs.llvm.org/show_bug.cgi?id=48320 for details.
|
||||
#define CARBON_PARSE_NODE_KIND(Name) \
|
||||
static constexpr auto Name()->ParseNodeKind { return KindEnum::Name; }
|
||||
#define CARBON_PARSE_NODE_KIND(Name) \
|
||||
static constexpr auto Name()->ParseNodeKind { \
|
||||
return ParseNodeKind(KindEnum::Name); \
|
||||
}
|
||||
#include "parser/parse_node_kind.def"
|
||||
|
||||
// The default constructor is deleted as objects of this type should always be
|
||||
@@ -51,12 +53,13 @@ class ParseNodeKind {
|
||||
#include "parser/parse_node_kind.def"
|
||||
};
|
||||
|
||||
constexpr ParseNodeKind(KindEnum k) : kind(k) {}
|
||||
constexpr explicit ParseNodeKind(KindEnum k) : kind(k) {}
|
||||
|
||||
// Enable conversion to our private enum, including in a `constexpr` context,
|
||||
// to enable usage in `switch` and `case`. The enum remains private and
|
||||
// nothing else should be using this.
|
||||
explicit constexpr operator KindEnum() const { return kind; }
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
constexpr operator KindEnum() const { return kind; }
|
||||
|
||||
KindEnum kind;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user