[llvm-branch-commits] [clang] [clang] NFC: Provide inline definitions for {get, cast}TagDecl and friends (PR #155051)

Matheus Izvekov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Aug 23 10:00:04 PDT 2025


================
@@ -23,6 +23,55 @@
 
 namespace clang {
 
+inline CXXRecordDecl *Type::getAsCXXRecordDecl() const {
+  const auto *TT = dyn_cast<TagType>(CanonicalType);
+  if (!isa_and_present<RecordType, InjectedClassNameType>(TT))
+    return nullptr;
+  auto *TD = TT->getOriginalDecl();
+  if (!isa<InjectedClassNameType>(TT) && !isa<CXXRecordDecl>(TD))
+    return nullptr;
----------------
mizvekov wrote:

For an InjectedClassNameType, we already know the declaration must be a CXXRecordDecl, so we can skip the check and go straight for the cast.

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


More information about the llvm-branch-commits mailing list