Skip to content

Commit 475de60

Browse files
committed
Merge commit 6e4930c67508 from llvm-project (by Alexander Kornienko):
Revert "[SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (#77768)" This reverts commit 924701311aa79180e86ad8ce43d253f27d25ec7d. Causes compilation errors on valid code, see llvm/llvm-project#77768 (comment).
1 parent c31859d commit 475de60

File tree

2 files changed

+20
-58
lines changed

2 files changed

+20
-58
lines changed

contrib/llvm-project/clang/lib/Sema/SemaInit.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4200,7 +4200,7 @@ static OverloadingResult ResolveConstructorOverload(
42004200
/// \param IsListInit Is this list-initialization?
42014201
/// \param IsInitListCopy Is this non-list-initialization resulting from a
42024202
/// list-initialization from {x} where x is the same
4203-
/// aggregate type as the entity?
4203+
/// type as the entity?
42044204
static void TryConstructorInitialization(Sema &S,
42054205
const InitializedEntity &Entity,
42064206
const InitializationKind &Kind,
@@ -4230,14 +4230,6 @@ static void TryConstructorInitialization(Sema &S,
42304230
Entity.getKind() !=
42314231
InitializedEntity::EK_LambdaToBlockConversionBlockElement);
42324232

4233-
bool CopyElisionPossible = false;
4234-
auto ElideConstructor = [&] {
4235-
// Convert qualifications if necessary.
4236-
Sequence.AddQualificationConversionStep(DestType, VK_PRValue);
4237-
if (ILE)
4238-
Sequence.RewrapReferenceInitList(DestType, ILE);
4239-
};
4240-
42414233
// C++17 [dcl.init]p17:
42424234
// - If the initializer expression is a prvalue and the cv-unqualified
42434235
// version of the source type is the same class as the class of the
@@ -4250,17 +4242,11 @@ static void TryConstructorInitialization(Sema &S,
42504242
if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
42514243
UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
42524244
S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) {
4253-
if (ILE && !DestType->isAggregateType()) {
4254-
// CWG2311: T{ prvalue_of_type_T } is not eligible for copy elision
4255-
// Make this an elision if this won't call an initializer-list
4256-
// constructor. (Always on an aggregate type or check constructors first.)
4257-
assert(!IsInitListCopy &&
4258-
"IsInitListCopy only possible with aggregate types");
4259-
CopyElisionPossible = true;
4260-
} else {
4261-
ElideConstructor();
4262-
return;
4263-
}
4245+
// Convert qualifications if necessary.
4246+
Sequence.AddQualificationConversionStep(DestType, VK_PRValue);
4247+
if (ILE)
4248+
Sequence.RewrapReferenceInitList(DestType, ILE);
4249+
return;
42644250
}
42654251

42664252
const RecordType *DestRecordType = DestType->getAs<RecordType>();
@@ -4305,12 +4291,6 @@ static void TryConstructorInitialization(Sema &S,
43054291
S, Kind.getLocation(), Args, CandidateSet, DestType, Ctors, Best,
43064292
CopyInitialization, AllowExplicit,
43074293
/*OnlyListConstructors=*/true, IsListInit, RequireActualConstructor);
4308-
4309-
if (CopyElisionPossible && Result == OR_No_Viable_Function) {
4310-
// No initializer list candidate
4311-
ElideConstructor();
4312-
return;
4313-
}
43144294
}
43154295

43164296
// C++11 [over.match.list]p1:
@@ -4592,9 +4572,9 @@ static void TryListInitialization(Sema &S,
45924572
return;
45934573
}
45944574

4595-
// C++11 [dcl.init.list]p3, per DR1467 and DR2137:
4596-
// - If T is an aggregate class and the initializer list has a single element
4597-
// of type cv U, where U is T or a class derived from T, the object is
4575+
// C++11 [dcl.init.list]p3, per DR1467:
4576+
// - If T is a class type and the initializer list has a single element of
4577+
// type cv U, where U is T or a class derived from T, the object is
45984578
// initialized from that element (by copy-initialization for
45994579
// copy-list-initialization, or by direct-initialization for
46004580
// direct-list-initialization).
@@ -4605,7 +4585,7 @@ static void TryListInitialization(Sema &S,
46054585
// - Otherwise, if T is an aggregate, [...] (continue below).
46064586
if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 &&
46074587
!IsDesignatedInit) {
4608-
if (DestType->isRecordType() && DestType->isAggregateType()) {
4588+
if (DestType->isRecordType()) {
46094589
QualType InitType = InitList->getInit(0)->getType();
46104590
if (S.Context.hasSameUnqualifiedType(InitType, DestType) ||
46114591
S.IsDerivedFrom(InitList->getBeginLoc(), InitType, DestType)) {

contrib/llvm-project/clang/lib/Sema/SemaOverload.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,37 +1568,19 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
15681568
// called for those cases.
15691569
if (CXXConstructorDecl *Constructor
15701570
= dyn_cast<CXXConstructorDecl>(ICS.UserDefined.ConversionFunction)) {
1571-
QualType FromType;
1572-
SourceLocation FromLoc;
1573-
// C++11 [over.ics.list]p6, per DR2137:
1574-
// C++17 [over.ics.list]p6:
1575-
// If C is not an initializer-list constructor and the initializer list
1576-
// has a single element of type cv U, where U is X or a class derived
1577-
// from X, the implicit conversion sequence has Exact Match rank if U is
1578-
// X, or Conversion rank if U is derived from X.
1579-
if (const auto *InitList = dyn_cast<InitListExpr>(From);
1580-
InitList && InitList->getNumInits() == 1 &&
1581-
!S.isInitListConstructor(Constructor)) {
1582-
const Expr *SingleInit = InitList->getInit(0);
1583-
FromType = SingleInit->getType();
1584-
FromLoc = SingleInit->getBeginLoc();
1585-
} else {
1586-
FromType = From->getType();
1587-
FromLoc = From->getBeginLoc();
1588-
}
1589-
QualType FromCanon =
1590-
S.Context.getCanonicalType(FromType.getUnqualifiedType());
1571+
QualType FromCanon
1572+
= S.Context.getCanonicalType(From->getType().getUnqualifiedType());
15911573
QualType ToCanon
15921574
= S.Context.getCanonicalType(ToType).getUnqualifiedType();
15931575
if (Constructor->isCopyConstructor() &&
15941576
(FromCanon == ToCanon ||
1595-
S.IsDerivedFrom(FromLoc, FromCanon, ToCanon))) {
1577+
S.IsDerivedFrom(From->getBeginLoc(), FromCanon, ToCanon))) {
15961578
// Turn this into a "standard" conversion sequence, so that it
15971579
// gets ranked with standard conversion sequences.
15981580
DeclAccessPair Found = ICS.UserDefined.FoundConversionFunction;
15991581
ICS.setStandard();
16001582
ICS.Standard.setAsIdentityConversion();
1601-
ICS.Standard.setFromType(FromType);
1583+
ICS.Standard.setFromType(From->getType());
16021584
ICS.Standard.setAllToTypes(ToType);
16031585
ICS.Standard.CopyConstructor = Constructor;
16041586
ICS.Standard.FoundCopyConstructor = Found;
@@ -5324,18 +5306,18 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
53245306
IsDesignatedInit)
53255307
return Result;
53265308

5327-
// Per DR1467 and DR2137:
5328-
// If the parameter type is an aggregate class X and the initializer list
5329-
// has a single element of type cv U, where U is X or a class derived from
5330-
// X, the implicit conversion sequence is the one required to convert the
5331-
// element to the parameter type.
5309+
// Per DR1467:
5310+
// If the parameter type is a class X and the initializer list has a single
5311+
// element of type cv U, where U is X or a class derived from X, the
5312+
// implicit conversion sequence is the one required to convert the element
5313+
// to the parameter type.
53325314
//
53335315
// Otherwise, if the parameter type is a character array [... ]
53345316
// and the initializer list has a single element that is an
53355317
// appropriately-typed string literal (8.5.2 [dcl.init.string]), the
53365318
// implicit conversion sequence is the identity conversion.
53375319
if (From->getNumInits() == 1 && !IsDesignatedInit) {
5338-
if (ToType->isRecordType() && ToType->isAggregateType()) {
5320+
if (ToType->isRecordType()) {
53395321
QualType InitType = From->getInit(0)->getType();
53405322
if (S.Context.hasSameUnqualifiedType(InitType, ToType) ||
53415323
S.IsDerivedFrom(From->getBeginLoc(), InitType, ToType))

0 commit comments

Comments
 (0)