[llvm-branch-commits] [libcxx] [clang] PR for llvm/llvm-project#79762 (PR #79763)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/79763 resolves llvm/llvm-project#79762 >From a9c2fe6d85b9136199acfcdacf01a2db0bdfc52a Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Wed, 24 Jan 2024 18:59:36 +0100 Subject: [PATCH] Revert "[SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (#77768)" This reverts commit 924701311aa79180e86ad8ce43d253f27d25ec7d. Causes compilation errors on valid code, see https://github.com/llvm/llvm-project/pull/77768#issuecomment-1908062472. (cherry picked from commit 6e4930c67508a90bdfd756f6e45417b5253cd741) --- clang/lib/Sema/SemaInit.cpp | 40 +++-- clang/lib/Sema/SemaOverload.cpp | 38 +++-- clang/test/CXX/drs/dr14xx.cpp | 10 +++ clang/test/CXX/drs/dr21xx.cpp | 45 -- clang/test/CXX/drs/dr23xx.cpp | 85 --- clang/www/cxx_dr_status.html | 4 +- .../pairs.pair/ctor.pair_U_V_move.pass.cpp| 21 + 7 files changed, 33 insertions(+), 210 deletions(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 91e4cb7b68a24a9..457fa377355a97c 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -4200,7 +4200,7 @@ static OverloadingResult ResolveConstructorOverload( /// \param IsListInit Is this list-initialization? /// \param IsInitListCopy Is this non-list-initialization resulting from a /// list-initialization from {x} where x is the same -/// aggregate type as the entity? +/// type as the entity? static void TryConstructorInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, @@ -4230,14 +4230,6 @@ static void TryConstructorInitialization(Sema &S, Entity.getKind() != InitializedEntity::EK_LambdaToBlockConversionBlockElement); - bool CopyElisionPossible = false; - auto ElideConstructor = [&] { -// Convert qualifications if necessary. -Sequence.AddQualificationConversionStep(DestType, VK_PRValue); -if (ILE) - Sequence.RewrapReferenceInitList(DestType, ILE); - }; - // C++17 [dcl.init]p17: // - If the initializer expression is a prvalue and the cv-unqualified // version of the source type is the same class as the class of the @@ -4250,17 +4242,11 @@ static void TryConstructorInitialization(Sema &S, if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor && UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() && S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) { -if (ILE && !DestType->isAggregateType()) { - // CWG2311: T{ prvalue_of_type_T } is not eligible for copy elision - // Make this an elision if this won't call an initializer-list - // constructor. (Always on an aggregate type or check constructors first.) - assert(!IsInitListCopy && - "IsInitListCopy only possible with aggregate types"); - CopyElisionPossible = true; -} else { - ElideConstructor(); - return; -} +// Convert qualifications if necessary. +Sequence.AddQualificationConversionStep(DestType, VK_PRValue); +if (ILE) + Sequence.RewrapReferenceInitList(DestType, ILE); +return; } const RecordType *DestRecordType = DestType->getAs(); @@ -4305,12 +4291,6 @@ static void TryConstructorInitialization(Sema &S, S, Kind.getLocation(), Args, CandidateSet, DestType, Ctors, Best, CopyInitialization, AllowExplicit, /*OnlyListConstructors=*/true, IsListInit, RequireActualConstructor); - -if (CopyElisionPossible && Result == OR_No_Viable_Function) { - // No initializer list candidate - ElideConstructor(); - return; -} } // C++11 [over.match.list]p1: @@ -4592,9 +4572,9 @@ static void TryListInitialization(Sema &S, return; } - // C++11 [dcl.init.list]p3, per DR1467 and DR2137: - // - If T is an aggregate class and the initializer list has a single element - // of type cv U, where U is T or a class derived from T, the object is + // C++11 [dcl.init.list]p3, per DR1467: + // - If T is a class type and the initializer list has a single element of + // type cv U, where U is T or a class derived from T, the object is // initialized from that element (by copy-initialization for // copy-list-initialization, or by direct-initialization for // direct-list-initialization). @@ -4605,7 +4585,7 @@ static void TryListInitialization(Sema &S, // - Otherwise, if T is an aggregate, [...] (continue below). if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 && !IsDesignatedInit) { -if (DestType->isRecordType() && DestType->isAggregateType()) { +if (DestType->isRecordType()) {
[llvm-branch-commits] [libcxx] [clang] PR for llvm/llvm-project#79762 (PR #79763)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/79763 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [clang] PR for llvm/llvm-project#79762 (PR #79763)
llvmbot wrote: @llvm/pr-subscribers-libcxx Author: None (llvmbot) Changes resolves llvm/llvm-project#79762 --- Full diff: https://github.com/llvm/llvm-project/pull/79763.diff 7 Files Affected: - (modified) clang/lib/Sema/SemaInit.cpp (+10-30) - (modified) clang/lib/Sema/SemaOverload.cpp (+10-28) - (modified) clang/test/CXX/drs/dr14xx.cpp (+10) - (modified) clang/test/CXX/drs/dr21xx.cpp (-45) - (modified) clang/test/CXX/drs/dr23xx.cpp (-85) - (modified) clang/www/cxx_dr_status.html (+2-2) - (modified) libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp (+1-20) ``diff diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 91e4cb7b68a24a9..457fa377355a97c 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -4200,7 +4200,7 @@ static OverloadingResult ResolveConstructorOverload( /// \param IsListInit Is this list-initialization? /// \param IsInitListCopy Is this non-list-initialization resulting from a /// list-initialization from {x} where x is the same -/// aggregate type as the entity? +/// type as the entity? static void TryConstructorInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, @@ -4230,14 +4230,6 @@ static void TryConstructorInitialization(Sema &S, Entity.getKind() != InitializedEntity::EK_LambdaToBlockConversionBlockElement); - bool CopyElisionPossible = false; - auto ElideConstructor = [&] { -// Convert qualifications if necessary. -Sequence.AddQualificationConversionStep(DestType, VK_PRValue); -if (ILE) - Sequence.RewrapReferenceInitList(DestType, ILE); - }; - // C++17 [dcl.init]p17: // - If the initializer expression is a prvalue and the cv-unqualified // version of the source type is the same class as the class of the @@ -4250,17 +4242,11 @@ static void TryConstructorInitialization(Sema &S, if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor && UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() && S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) { -if (ILE && !DestType->isAggregateType()) { - // CWG2311: T{ prvalue_of_type_T } is not eligible for copy elision - // Make this an elision if this won't call an initializer-list - // constructor. (Always on an aggregate type or check constructors first.) - assert(!IsInitListCopy && - "IsInitListCopy only possible with aggregate types"); - CopyElisionPossible = true; -} else { - ElideConstructor(); - return; -} +// Convert qualifications if necessary. +Sequence.AddQualificationConversionStep(DestType, VK_PRValue); +if (ILE) + Sequence.RewrapReferenceInitList(DestType, ILE); +return; } const RecordType *DestRecordType = DestType->getAs(); @@ -4305,12 +4291,6 @@ static void TryConstructorInitialization(Sema &S, S, Kind.getLocation(), Args, CandidateSet, DestType, Ctors, Best, CopyInitialization, AllowExplicit, /*OnlyListConstructors=*/true, IsListInit, RequireActualConstructor); - -if (CopyElisionPossible && Result == OR_No_Viable_Function) { - // No initializer list candidate - ElideConstructor(); - return; -} } // C++11 [over.match.list]p1: @@ -4592,9 +4572,9 @@ static void TryListInitialization(Sema &S, return; } - // C++11 [dcl.init.list]p3, per DR1467 and DR2137: - // - If T is an aggregate class and the initializer list has a single element - // of type cv U, where U is T or a class derived from T, the object is + // C++11 [dcl.init.list]p3, per DR1467: + // - If T is a class type and the initializer list has a single element of + // type cv U, where U is T or a class derived from T, the object is // initialized from that element (by copy-initialization for // copy-list-initialization, or by direct-initialization for // direct-list-initialization). @@ -4605,7 +4585,7 @@ static void TryListInitialization(Sema &S, // - Otherwise, if T is an aggregate, [...] (continue below). if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 && !IsDesignatedInit) { -if (DestType->isRecordType() && DestType->isAggregateType()) { +if (DestType->isRecordType()) { QualType InitType = InitList->getInit(0)->getType(); if (S.Context.hasSameUnqualifiedType(InitType, DestType) || S.IsDerivedFrom(InitList->getBeginLoc(), InitType, DestType)) { diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 030878899b81223..c9eb67898356334 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -1568,37 +1568,19 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualTyp
[llvm-branch-commits] [libcxx] [clang] PR for llvm/llvm-project#79762 (PR #79763)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 27654471cc7acfca733c104e2ec24f882cfc6132 a9c2fe6d85b9136199acfcdacf01a2db0bdfc52a -- clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaOverload.cpp clang/test/CXX/drs/dr14xx.cpp clang/test/CXX/drs/dr21xx.cpp clang/test/CXX/drs/dr23xx.cpp libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index c9eb678983..018043c3b3 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -1568,8 +1568,8 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType ToType, // called for those cases. if (CXXConstructorDecl *Constructor = dyn_cast(ICS.UserDefined.ConversionFunction)) { - QualType FromCanon -= S.Context.getCanonicalType(From->getType().getUnqualifiedType()); + QualType FromCanon = + S.Context.getCanonicalType(From->getType().getUnqualifiedType()); QualType ToCanon = S.Context.getCanonicalType(ToType).getUnqualifiedType(); if (Constructor->isCopyConstructor() && `` https://github.com/llvm/llvm-project/pull/79763 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [clang] PR for llvm/llvm-project#79762 (PR #79763)
https://github.com/Endilll approved this pull request. Changes to DR tests look good to me. https://github.com/llvm/llvm-project/pull/79763 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits