ayzhao created this revision. Herald added a project: All. ayzhao requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
When calling InitializeBase(...), TryOrBuidlParenListInit(...) needs to pass in the parent entity; otherwise, we erroneously try to cast CurContext to a CXXConstructorDecl[0], which can't be done since we're performing aggregate initialization, not constructor initialization. Field initialization is not affected, but this patch still adds some tests for it. Fixes 62296 [0]: https://github.com/llvm/llvm-project/blob/33d6bd1c667456f7f4a9d338a7996a30a3af50a3/clang/lib/Sema/SemaAccess.cpp#L1696 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D149301 Files: clang/lib/Sema/SemaInit.cpp clang/test/SemaCXX/paren-list-agg-init.cpp Index: clang/test/SemaCXX/paren-list-agg-init.cpp =================================================================== --- clang/test/SemaCXX/paren-list-agg-init.cpp +++ clang/test/SemaCXX/paren-list-agg-init.cpp @@ -200,3 +200,26 @@ // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}} } } + +namespace gh62296 { +struct L { +protected: + L(int); + // expected-note@-1 2{{declared protected here}} +}; + +struct M : L {}; + +struct N { + L l; +}; + +M m(42); +// expected-error@-1 {{base class 'L' has protected constructor}} +// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}} + +N n(43); +// expected-error@-1 {{field of type 'L' has protected constructor}} +// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}} + +} Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -5449,8 +5449,9 @@ } else if (auto *RT = Entity.getType()->getAs<RecordType>()) { const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); - auto BaseRange = map_range(RD->bases(), [&S](auto &base) { - return InitializedEntity::InitializeBase(S.getASTContext(), &base, false); + auto BaseRange = map_range(RD->bases(), [&](auto &base) { + return InitializedEntity::InitializeBase(S.getASTContext(), &base, false, + &Entity); }); auto FieldRange = map_range(RD->fields(), [](auto *field) { return InitializedEntity::InitializeMember(field);
Index: clang/test/SemaCXX/paren-list-agg-init.cpp =================================================================== --- clang/test/SemaCXX/paren-list-agg-init.cpp +++ clang/test/SemaCXX/paren-list-agg-init.cpp @@ -200,3 +200,26 @@ // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}} } } + +namespace gh62296 { +struct L { +protected: + L(int); + // expected-note@-1 2{{declared protected here}} +}; + +struct M : L {}; + +struct N { + L l; +}; + +M m(42); +// expected-error@-1 {{base class 'L' has protected constructor}} +// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}} + +N n(43); +// expected-error@-1 {{field of type 'L' has protected constructor}} +// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}} + +} Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -5449,8 +5449,9 @@ } else if (auto *RT = Entity.getType()->getAs<RecordType>()) { const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); - auto BaseRange = map_range(RD->bases(), [&S](auto &base) { - return InitializedEntity::InitializeBase(S.getASTContext(), &base, false); + auto BaseRange = map_range(RD->bases(), [&](auto &base) { + return InitializedEntity::InitializeBase(S.getASTContext(), &base, false, + &Entity); }); auto FieldRange = map_range(RD->fields(), [](auto *field) { return InitializedEntity::InitializeMember(field);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits