[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 26 10:52:53 PDT 2024
================
@@ -0,0 +1,193 @@
+//===--- EnumInitialValueCheck.cpp - clang-tidy ---------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "EnumInitialValueCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+EnumInitialValueCheck::EnumInitialValueCheck(StringRef Name,
+ ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ AllowExplicitZeroFirstInitialValue(
+ Options.get("AllowExplicitZeroFirstInitialValue", true)),
+ AllowExplicitLinearInitialValues(
+ Options.get("AllowExplicitLinearInitialValues", true)) {}
+
+void EnumInitialValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "AllowExplicitZeroFirstInitialValue",
+ AllowExplicitZeroFirstInitialValue);
+ Options.store(Opts, "AllowExplicitLinearInitialValues",
+ AllowExplicitLinearInitialValues);
+}
+
+namespace {
+
+bool isNoneEnumeratorsInitialized(const EnumDecl &Node) {
----------------
PiotrZSL wrote:
for functions we should use ``static`` instead of anonymous namespace.
For AST_MATCHER there should be anonymous namespace just because static is not possible.
Also move this code to beginning of file, to not cut in between of class methods.
https://github.com/llvm/llvm-project/pull/86129
More information about the cfe-commits
mailing list