[clang-tools-extra] [clang-tidy] Add `readability-redundant-tag` check (PR #210007)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 22:10:20 PDT 2026
================
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "RedundantTagCheck.h"
+
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static bool canHideTag(const NamedDecl *D) {
+ D = D->getUnderlyingDecl();
+
+ return isa<VarDecl>(D) || isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D) ||
+ isa<FunctionTemplateDecl>(D) || isa<FieldDecl>(D) ||
+ isa<UnresolvedUsingValueDecl>(D);
+}
----------------
zwuis wrote:
> @zwuis should I identify the declaration kinds that can hide a tag according to [basic.scope.hiding], and treat the other NamedDecl subclasses as the false cases you mentioned?
You can refer to this section. Our goal is minimizing the number of false positives. If it do minimize the number of false positives, the answer is yes.
Note that this section was modified by [P1787R6](https://wg21.link/p1787r6). You can visit https://eel.is/c++draft to take a look at the latest working draft.
https://github.com/llvm/llvm-project/pull/210007
More information about the cfe-commits
mailing list