git: ddbac700c256 - main - Merge commit 6e4930c67508 from llvm-project (by Alexander Kornienko):
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 06 Apr 2024 20:18:36 UTC
The branch main has been updated by dim:
URL: https://cgit.FreeBSD.org/src/commit/?id=ddbac700c256bec42c441b75a5cb5f74e9be601f
commit ddbac700c256bec42c441b75a5cb5f74e9be601f
Author: Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-01-28 20:34:42 +0000
Commit: Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-04-06 20:14:01 +0000
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
https://github.com/llvm/llvm-project/pull/77768#issuecomment-1908062472.
In particular, this fixes bogus "call to constructor of 'SomeType' is
ambiguous" errors.
PR: 276104
MFC after: 1 month
---
contrib/llvm-project/clang/lib/Sema/SemaInit.cpp | 40 ++++++----------------
.../llvm-project/clang/lib/Sema/SemaOverload.cpp | 38 ++++++--------------
2 files changed, 20 insertions(+), 58 deletions(-)
diff --git a/contrib/llvm-project/clang/lib/Sema/SemaInit.cpp b/contrib/llvm-project/clang/lib/Sema/SemaInit.cpp
index 91e4cb7b68a2..457fa377355a 100644
--- a/contrib/llvm-project/clang/lib/Sema/SemaInit.cpp
+++ b/contrib/llvm-project/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<RecordType>();
@@ -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/contrib/llvm-project/clang/lib/Sema/SemaOverload.cpp b/contrib/llvm-project/clang/lib/Sema/SemaOverload.cpp
index 030878899b81..c9eb67898356 100644
--- a/contrib/llvm-project/clang/lib/Sema/SemaOverload.cpp
+++ b/contrib/llvm-project/clang/lib/Sema/SemaOverload.cpp
@@ -1568,37 +1568,19 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
// called for those cases.
if (CXXConstructorDecl *Constructor
= dyn_cast<CXXConstructorDecl>(ICS.UserDefined.ConversionFunction)) {
- QualType FromType;
- SourceLocation FromLoc;
- // C++11 [over.ics.list]p6, per DR2137:
- // C++17 [over.ics.list]p6:
- // If C is not an initializer-list constructor and the initializer list
- // has a single element of type cv U, where U is X or a class derived
- // from X, the implicit conversion sequence has Exact Match rank if U is
- // X, or Conversion rank if U is derived from X.
- if (const auto *InitList = dyn_cast<InitListExpr>(From);
- InitList && InitList->getNumInits() == 1 &&
- !S.isInitListConstructor(Constructor)) {
- const Expr *SingleInit = InitList->getInit(0);
- FromType = SingleInit->getType();
- FromLoc = SingleInit->getBeginLoc();
- } else {
- FromType = From->getType();
- FromLoc = From->getBeginLoc();
- }
- QualType FromCanon =
- S.Context.getCanonicalType(FromType.getUnqualifiedType());
+ QualType FromCanon
+ = S.Context.getCanonicalType(From->getType().getUnqualifiedType());
QualType ToCanon
= S.Context.getCanonicalType(ToType).getUnqualifiedType();
if (Constructor->isCopyConstructor() &&
(FromCanon == ToCanon ||
- S.IsDerivedFrom(FromLoc, FromCanon, ToCanon))) {
+ S.IsDerivedFrom(From->getBeginLoc(), FromCanon, ToCanon))) {
// Turn this into a "standard" conversion sequence, so that it
// gets ranked with standard conversion sequences.
DeclAccessPair Found = ICS.UserDefined.FoundConversionFunction;
ICS.setStandard();
ICS.Standard.setAsIdentityConversion();
- ICS.Standard.setFromType(FromType);
+ ICS.Standard.setFromType(From->getType());
ICS.Standard.setAllToTypes(ToType);
ICS.Standard.CopyConstructor = Constructor;
ICS.Standard.FoundCopyConstructor = Found;
@@ -5324,18 +5306,18 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
IsDesignatedInit)
return Result;
- // Per DR1467 and DR2137:
- // If the parameter type is an aggregate class X and the initializer list
- // has a single element of type cv U, where U is X or a class derived from
- // X, the implicit conversion sequence is the one required to convert the
- // element to the parameter type.
+ // Per DR1467:
+ // If the parameter type is a class X and the initializer list has a single
+ // element of type cv U, where U is X or a class derived from X, the
+ // implicit conversion sequence is the one required to convert the element
+ // to the parameter type.
//
// Otherwise, if the parameter type is a character array [... ]
// and the initializer list has a single element that is an
// appropriately-typed string literal (8.5.2 [dcl.init.string]), the
// implicit conversion sequence is the identity conversion.
if (From->getNumInits() == 1 && !IsDesignatedInit) {
- if (ToType->isRecordType() && ToType->isAggregateType()) {
+ if (ToType->isRecordType()) {
QualType InitType = From->getInit(0)->getType();
if (S.Context.hasSameUnqualifiedType(InitType, ToType) ||
S.IsDerivedFrom(From->getBeginLoc(), InitType, ToType))