[PATCH] D142384: [C++20] Fix a crash with modules.

Utkarsh Saxena via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 31 09:49:04 PST 2023


usaxena95 updated this revision to Diff 493652.
usaxena95 added a comment.

Use definition based field access only for CXXRecordDecl.
Avoid dynamic dispatch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142384/new/

https://reviews.llvm.org/D142384

Files:
  clang/include/clang/AST/DeclCXX.h


Index: clang/include/clang/AST/DeclCXX.h
===================================================================
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -554,6 +554,21 @@
 
   bool hasDefinition() const { return DefinitionData || dataPtr(); }
 
+  RecordDecl::field_iterator field_begin() const {
+    assert(hasDefinition() && "Definition not available to get fields.");
+    return static_cast<const RecordDecl *>(getDefinition())->field_begin();
+  }
+
+  RecordDecl::field_iterator field_end() const {
+    return field_iterator(decl_iterator());
+  }
+
+  RecordDecl::field_range fields() const {
+    return field_range(field_begin(), field_end());
+  }
+
+  bool field_empty() const { return field_begin() == field_end(); }
+
   static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
                                SourceLocation StartLoc, SourceLocation IdLoc,
                                IdentifierInfo *Id,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142384.493652.patch
Type: text/x-patch
Size: 981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230131/ecabb7eb/attachment.bin>


More information about the cfe-commits mailing list