From b6121432da79c4b3d21f191864ff6c583e2e62eb Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Mon, 23 Jan 2023 19:15:46 +0100 Subject: [PATCH] [C++20] Fix a crash with modules. Differential Revision: https://reviews.llvm.org/D142384 --- clang/lib/AST/Decl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index e60cc28..51cff6c 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -4770,7 +4770,10 @@ bool RecordDecl::isOrContainsUnion() const { RecordDecl::field_iterator RecordDecl::field_begin() const { if (hasExternalLexicalStorage() && !hasLoadedFieldsFromExternalStorage()) LoadFieldsFromExternalStorage(); - + // This is necessary for correctness for C++ with modules. + // FIXME: Come up with a test case that breaks without definition. + if (RecordDecl *D = getDefinition(); D && D != this) + return D->field_begin(); return field_iterator(decl_iterator(FirstDecl)); } -- 2.7.4