@@ -4085,16 +4085,13 @@ static bool hasCopyOrMoveCtorParam(ASTContext &Ctx,
4085
4085
return Ctx.hasSameUnqualifiedType (ParmT, ClassT);
4086
4086
}
4087
4087
4088
- static OverloadingResult
4089
- ResolveConstructorOverload (Sema &S, SourceLocation DeclLoc,
4090
- MultiExprArg Args,
4091
- OverloadCandidateSet &CandidateSet,
4092
- QualType DestType,
4093
- DeclContext::lookup_result Ctors,
4094
- OverloadCandidateSet::iterator &Best,
4095
- bool CopyInitializing, bool AllowExplicit,
4096
- bool OnlyListConstructors, bool IsListInit,
4097
- bool SecondStepOfCopyInit = false ) {
4088
+ static OverloadingResult ResolveConstructorOverload (
4089
+ Sema &S, SourceLocation DeclLoc, MultiExprArg Args,
4090
+ OverloadCandidateSet &CandidateSet, QualType DestType,
4091
+ DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator &Best,
4092
+ bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors,
4093
+ bool IsListInit, bool RequireActualConstructor,
4094
+ bool SecondStepOfCopyInit = false ) {
4098
4095
CandidateSet.clear (OverloadCandidateSet::CSK_InitByConstructor);
4099
4096
CandidateSet.setDestAS (DestType.getQualifiers ().getAddressSpace ());
4100
4097
@@ -4157,7 +4154,7 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
4157
4154
// Note: SecondStepOfCopyInit is only ever true in this case when
4158
4155
// evaluating whether to produce a C++98 compatibility warning.
4159
4156
if (S.getLangOpts ().CPlusPlus17 && Args.size () == 1 &&
4160
- !SecondStepOfCopyInit) {
4157
+ !RequireActualConstructor && ! SecondStepOfCopyInit) {
4161
4158
Expr *Initializer = Args[0 ];
4162
4159
auto *SourceRD = Initializer->getType ()->getAsCXXRecordDecl ();
4163
4160
if (SourceRD && S.isCompleteType (DeclLoc, Initializer->getType ())) {
@@ -4225,6 +4222,12 @@ static void TryConstructorInitialization(Sema &S,
4225
4222
return ;
4226
4223
}
4227
4224
4225
+ bool RequireActualConstructor =
4226
+ !(Entity.getKind () != InitializedEntity::EK_Base &&
4227
+ Entity.getKind () != InitializedEntity::EK_Delegating &&
4228
+ Entity.getKind () !=
4229
+ InitializedEntity::EK_LambdaToBlockConversionBlockElement);
4230
+
4228
4231
// C++17 [dcl.init]p17:
4229
4232
// - If the initializer expression is a prvalue and the cv-unqualified
4230
4233
// version of the source type is the same class as the class of the
@@ -4234,11 +4237,7 @@ static void TryConstructorInitialization(Sema &S,
4234
4237
// class or delegating to another constructor from a mem-initializer.
4235
4238
// ObjC++: Lambda captured by the block in the lambda to block conversion
4236
4239
// should avoid copy elision.
4237
- if (S.getLangOpts ().CPlusPlus17 &&
4238
- Entity.getKind () != InitializedEntity::EK_Base &&
4239
- Entity.getKind () != InitializedEntity::EK_Delegating &&
4240
- Entity.getKind () !=
4241
- InitializedEntity::EK_LambdaToBlockConversionBlockElement &&
4240
+ if (S.getLangOpts ().CPlusPlus17 && !RequireActualConstructor &&
4242
4241
UnwrappedArgs.size () == 1 && UnwrappedArgs[0 ]->isPRValue () &&
4243
4242
S.Context .hasSameUnqualifiedType (UnwrappedArgs[0 ]->getType (), DestType)) {
4244
4243
// Convert qualifications if necessary.
@@ -4286,11 +4285,10 @@ static void TryConstructorInitialization(Sema &S,
4286
4285
// If the initializer list has no elements and T has a default constructor,
4287
4286
// the first phase is omitted.
4288
4287
if (!(UnwrappedArgs.empty () && S.LookupDefaultConstructor (DestRecordDecl)))
4289
- Result = ResolveConstructorOverload (S, Kind.getLocation (), Args,
4290
- CandidateSet, DestType, Ctors, Best,
4291
- CopyInitialization, AllowExplicit,
4292
- /* OnlyListConstructors=*/ true ,
4293
- IsListInit);
4288
+ Result = ResolveConstructorOverload (
4289
+ S, Kind.getLocation (), Args, CandidateSet, DestType, Ctors, Best,
4290
+ CopyInitialization, AllowExplicit,
4291
+ /* OnlyListConstructors=*/ true , IsListInit, RequireActualConstructor);
4294
4292
}
4295
4293
4296
4294
// C++11 [over.match.list]p1:
@@ -4300,11 +4298,10 @@ static void TryConstructorInitialization(Sema &S,
4300
4298
// elements of the initializer list.
4301
4299
if (Result == OR_No_Viable_Function) {
4302
4300
AsInitializerList = false ;
4303
- Result = ResolveConstructorOverload (S, Kind.getLocation (), UnwrappedArgs,
4304
- CandidateSet, DestType, Ctors, Best,
4305
- CopyInitialization, AllowExplicit,
4306
- /* OnlyListConstructors=*/ false ,
4307
- IsListInit);
4301
+ Result = ResolveConstructorOverload (
4302
+ S, Kind.getLocation (), UnwrappedArgs, CandidateSet, DestType, Ctors,
4303
+ Best, CopyInitialization, AllowExplicit,
4304
+ /* OnlyListConstructors=*/ false , IsListInit, RequireActualConstructor);
4308
4305
}
4309
4306
if (Result) {
4310
4307
Sequence.SetOverloadFailure (
@@ -6778,6 +6775,7 @@ static ExprResult CopyObject(Sema &S,
6778
6775
S, Loc, CurInitExpr, CandidateSet, T, Ctors, Best,
6779
6776
/* CopyInitializing=*/ false , /* AllowExplicit=*/ true ,
6780
6777
/* OnlyListConstructors=*/ false , /* IsListInit=*/ false ,
6778
+ /* RequireActualConstructor=*/ false ,
6781
6779
/* SecondStepOfCopyInit=*/ true )) {
6782
6780
case OR_Success:
6783
6781
break ;
@@ -6920,6 +6918,7 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
6920
6918
S, Loc, CurInitExpr, CandidateSet, CurInitExpr->getType (), Ctors, Best,
6921
6919
/* CopyInitializing=*/ false , /* AllowExplicit=*/ true ,
6922
6920
/* OnlyListConstructors=*/ false , /* IsListInit=*/ false ,
6921
+ /* RequireActualConstructor=*/ false ,
6923
6922
/* SecondStepOfCopyInit=*/ true );
6924
6923
6925
6924
PartialDiagnostic Diag = S.PDiag (diag::warn_cxx98_compat_temp_copy)
0 commit comments