[clang-tools-extra] Add check 'modernize-use-enum-class' (PR #138282)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Mon May 5 08:30:21 PDT 2025


================
@@ -0,0 +1,34 @@
+//===--- UseEnumClassCheck.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 "UseEnumClassCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+void UseEnumClassCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+      traverse(TK_AsIs,
----------------
vbvictor wrote:

As I understand (maybe I'm wrong, correct me please) when `TK_IgnoreUnlessSpelledInSource` is specified, we would not traverse e.g. implicit instantiations of a templated class which has `enum class`, so the check will be faster with `TK_IgnoreUnlessSpelledInSource`. 
If I'm wrong and there are no performance benefits, we can still remove `traverse` call from `Finder->addMatcher` because it's default value, and we don't need to write it explicitly.


https://github.com/llvm/llvm-project/pull/138282


More information about the cfe-commits mailing list