================
@@ -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());
----------------
bjosv wrote:
Oh, thanks, that was nicer
https://github.com/llvm/llvm-project/pull/189459
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits