https://github.com/zwuis created
https://github.com/llvm/llvm-project/pull/148195
Co-authored-by: Matheus Izvekov
>From 306049aa7dd17f6683935d631b3ad222b268a3f2 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu
Date: Fri, 11 Jul 2025 18:17:05 +0800
Subject: [PATCH] (`RecordDecl` -> `CXXRecordDecl`)`::isInjectedClassName`
---
clang-tools-extra/clangd/CodeComplete.cpp | 2 +-
clang-tools-extra/clangd/Quality.cpp | 2 +-
.../clangd/SemanticHighlighting.cpp| 2 +-
clang/include/clang/AST/Decl.h | 15 ---
clang/include/clang/AST/DeclCXX.h | 18 --
clang/lib/AST/Decl.cpp | 5 -
clang/lib/AST/DeclCXX.cpp | 10 ++
clang/lib/Sema/SemaAccess.cpp | 3 ++-
.../Clang/ClangASTImporter.cpp | 2 +-
.../TypeSystem/Clang/TypeSystemClang.cpp | 5 -
10 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp
b/clang-tools-extra/clangd/CodeComplete.cpp
index 14679fea6ac8a..d5907e3143bf6 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -870,7 +870,7 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K)
{
}
static bool isInjectedClass(const NamedDecl &D) {
- if (auto *R = dyn_cast_or_null(&D))
+ if (auto *R = dyn_cast_or_null(&D))
if (R->isInjectedClassName())
return true;
return false;
diff --git a/clang-tools-extra/clangd/Quality.cpp
b/clang-tools-extra/clangd/Quality.cpp
index c1ab63fb22f61..3f630b05c654b 100644
--- a/clang-tools-extra/clangd/Quality.cpp
+++ b/clang-tools-extra/clangd/Quality.cpp
@@ -258,7 +258,7 @@ static SymbolRelevanceSignals::AccessibleScope
computeScope(const NamedDecl *D) {
// Injected "Foo" within the class "Foo" has file scope, not class scope.
const DeclContext *DC = D->getDeclContext();
- if (auto *R = dyn_cast_or_null(D))
+ if (auto *R = dyn_cast_or_null(D))
if (R->isInjectedClassName())
DC = DC->getParent();
// Class constructor should have the same scope as the class.
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index dc574dcd11703..e6d5cf7053694 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -597,7 +597,7 @@ class HighlightingsBuilder {
std::optional scopeModifier(const NamedDecl *D) {
const DeclContext *DC = D->getDeclContext();
// Injected "Foo" within the class "Foo" has file scope, not class scope.
- if (auto *R = dyn_cast_or_null(D))
+ if (auto *R = dyn_cast_or_null(D))
if (R->isInjectedClassName())
DC = DC->getParent();
// Lambda captures are considered function scope, not class scope.
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index de79a9df29a5b..3d7969cca83fd 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4420,21 +4420,6 @@ class RecordDecl : public TagDecl {
void reorderDecls(const SmallVectorImpl &Decls);
- /// Determines whether this declaration represents the
- /// injected class name.
- ///
- /// The injected class name in C++ is the name of the class that
- /// appears inside the class itself. For example:
- ///
- /// \code
- /// struct C {
- /// // C is implicitly declared here as a synonym for the class name.
- /// };
- ///
- /// C::C c; // same as "C c;"
- /// \endcode
- bool isInjectedClassName() const;
-
/// Determine whether this record is a class describing a lambda
/// function object.
bool isLambda() const;
diff --git a/clang/include/clang/AST/DeclCXX.h
b/clang/include/clang/AST/DeclCXX.h
index 05cddd024d7cf..77bc3cad72ed9 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -546,8 +546,7 @@ class CXXRecordDecl : public RecordDecl {
}
CXXRecordDecl *getMostRecentNonInjectedDecl() {
-CXXRecordDecl *Recent =
-static_cast(this)->getMostRecentDecl();
+CXXRecordDecl *Recent = getMostRecentDecl();
while (Recent->isInjectedClassName()) {
// FIXME: Does injected class name need to be in the redeclarations
chain?
assert(Recent->getPreviousDecl());
@@ -1889,6 +1888,21 @@ class CXXRecordDecl : public RecordDecl {
DL.IsGenericLambda = IsGeneric;
}
+ /// Determines whether this declaration represents the
+ /// injected class name.
+ ///
+ /// The injected class name in C++ is the name of the class that
+ /// appears inside the class itself. For example:
+ ///
+ /// \code
+ /// struct C {
+ /// // C is implicitly declared here as a synonym for the class name.
+ /// };
+ ///
+ /// C::C c; // same as "C c;"
+ /// \endcode
+ bool isInjectedClassName() const;
+
// Determine whether this type is an Interface Like type for
// __interface inheritance purposes.
bo