=?utf-8?q?Björn?= Svensson <[email protected]>,
=?utf-8?q?Björn?= Svensson <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>


================
@@ -20,15 +20,39 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
-static bool isNoneEnumeratorsInitialized(const EnumDecl &Node) {
-  return llvm::all_of(Node.enumerators(), [](const EnumConstantDecl *ECD) {
-    return ECD->getInitExpr() == nullptr;
+/// Check if \p ECD is initialized by referencing another enumerator in the
+/// same enum (e.g., `last = first`).
+static bool isSelfReference(const EnumConstantDecl *ECD) {
+  const Expr *Init = ECD->getInitExpr();
+  if (!Init)
+    return false;
+  const auto *CE = dyn_cast<ConstantExpr>(Init);
+  if (!CE)
+    return false;
+  const auto *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr());
+  if (!DRE)
+    return false;
+  const auto *RefECD = dyn_cast<EnumConstantDecl>(DRE->getDecl());
+  return RefECD && RefECD->getDeclContext() == ECD->getDeclContext();
+}
+
+static bool isAllowedReference(const EnumConstantDecl *ECD, bool AllowRefs) {
+  return AllowRefs && isSelfReference(ECD);
+}
+
+static bool isNoneEnumeratorsInitialized(const EnumDecl &Node, bool AllowRefs) 
{
----------------
vbvictor wrote:

same elsewhere

https://github.com/llvm/llvm-project/pull/189459
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to