@@ -4092,16 +4092,13 @@ static bool hasCopyOrMoveCtorParam(ASTContext &Ctx,
4092
4092
return Ctx.hasSameUnqualifiedType (ParmT, ClassT);
4093
4093
}
4094
4094
4095
- static OverloadingResult
4096
- ResolveConstructorOverload (Sema &S, SourceLocation DeclLoc,
4097
- MultiExprArg Args,
4098
- OverloadCandidateSet &CandidateSet,
4099
- QualType DestType,
4100
- DeclContext::lookup_result Ctors,
4101
- OverloadCandidateSet::iterator &Best,
4102
- bool CopyInitializing, bool AllowExplicit,
4103
- bool OnlyListConstructors, bool IsListInit,
4104
- bool SecondStepOfCopyInit = false ) {
4095
+ static OverloadingResult ResolveConstructorOverload (
4096
+ Sema &S, SourceLocation DeclLoc, MultiExprArg Args,
4097
+ OverloadCandidateSet &CandidateSet, QualType DestType,
4098
+ DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator &Best,
4099
+ bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors,
4100
+ bool IsListInit, bool RequireActualConstructor,
4101
+ bool SecondStepOfCopyInit = false ) {
4105
4102
CandidateSet.clear (OverloadCandidateSet::CSK_InitByConstructor);
4106
4103
CandidateSet.setDestAS (DestType.getQualifiers ().getAddressSpace ());
4107
4104
@@ -4164,7 +4161,7 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
4164
4161
// Note: SecondStepOfCopyInit is only ever true in this case when
4165
4162
// evaluating whether to produce a C++98 compatibility warning.
4166
4163
if (S.getLangOpts ().CPlusPlus17 && Args.size () == 1 &&
4167
- !SecondStepOfCopyInit) {
4164
+ !RequireActualConstructor && ! SecondStepOfCopyInit) {
4168
4165
Expr *Initializer = Args[0 ];
4169
4166
auto *SourceRD = Initializer->getType ()->getAsCXXRecordDecl ();
4170
4167
if (SourceRD && S.isCompleteType (DeclLoc, Initializer->getType ())) {
@@ -4232,6 +4229,12 @@ static void TryConstructorInitialization(Sema &S,
4232
4229
return ;
4233
4230
}
4234
4231
4232
+ bool RequireActualConstructor =
4233
+ !(Entity.getKind () != InitializedEntity::EK_Base &&
4234
+ Entity.getKind () != InitializedEntity::EK_Delegating &&
4235
+ Entity.getKind () !=
4236
+ InitializedEntity::EK_LambdaToBlockConversionBlockElement);
4237
+
4235
4238
// C++17 [dcl.init]p17:
4236
4239
// - If the initializer expression is a prvalue and the cv-unqualified
4237
4240
// version of the source type is the same class as the class of the
@@ -4241,11 +4244,7 @@ static void TryConstructorInitialization(Sema &S,
4241
4244
// class or delegating to another constructor from a mem-initializer.
4242
4245
// ObjC++: Lambda captured by the block in the lambda to block conversion
4243
4246
// should avoid copy elision.
4244
- if (S.getLangOpts ().CPlusPlus17 &&
4245
- Entity.getKind () != InitializedEntity::EK_Base &&
4246
- Entity.getKind () != InitializedEntity::EK_Delegating &&
4247
- Entity.getKind () !=
4248
- InitializedEntity::EK_LambdaToBlockConversionBlockElement &&
4247
+ if (S.getLangOpts ().CPlusPlus17 && !RequireActualConstructor &&
4249
4248
UnwrappedArgs.size () == 1 && UnwrappedArgs[0 ]->isPRValue () &&
4250
4249
S.Context .hasSameUnqualifiedType (UnwrappedArgs[0 ]->getType (), DestType)) {
4251
4250
// Convert qualifications if necessary.
@@ -4293,11 +4292,10 @@ static void TryConstructorInitialization(Sema &S,
4293
4292
// If the initializer list has no elements and T has a default constructor,
4294
4293
// the first phase is omitted.
4295
4294
if (!(UnwrappedArgs.empty () && S.LookupDefaultConstructor (DestRecordDecl)))
4296
- Result = ResolveConstructorOverload (S, Kind.getLocation (), Args,
4297
- CandidateSet, DestType, Ctors, Best,
4298
- CopyInitialization, AllowExplicit,
4299
- /* OnlyListConstructors=*/ true ,
4300
- IsListInit);
4295
+ Result = ResolveConstructorOverload (
4296
+ S, Kind.getLocation (), Args, CandidateSet, DestType, Ctors, Best,
4297
+ CopyInitialization, AllowExplicit,
4298
+ /* OnlyListConstructors=*/ true , IsListInit, RequireActualConstructor);
4301
4299
}
4302
4300
4303
4301
// C++11 [over.match.list]p1:
@@ -4307,11 +4305,10 @@ static void TryConstructorInitialization(Sema &S,
4307
4305
// elements of the initializer list.
4308
4306
if (Result == OR_No_Viable_Function) {
4309
4307
AsInitializerList = false ;
4310
- Result = ResolveConstructorOverload (S, Kind.getLocation (), UnwrappedArgs,
4311
- CandidateSet, DestType, Ctors, Best,
4312
-
10000
CopyInitialization, AllowExplicit,
4313
- /* OnlyListConstructors=*/ false ,
4314
- IsListInit);
4308
+ Result = ResolveConstructorOverload (
4309
+ S, Kind.getLocation (), UnwrappedArgs, CandidateSet, DestType, Ctors,
4310
+ Best, CopyInitialization, AllowExplicit,
4311
+ /* OnlyListConstructors=*/ false , IsListInit, RequireActualConstructor);
4315
4312
}
4316
4313
if (Result) {
4317
4314
Sequence.SetOverloadFailure (
@@ -6776,6 +6773,7 @@ static ExprResult CopyObject(Sema &S,
6776
6773
S, Loc, CurInitExpr, CandidateSet, T, Ctors, Best,
6777
6774
/* CopyInitializing=*/ false , /* AllowExplicit=*/ true ,
6778
6775
/* OnlyListConstructors=*/ false , /* IsListInit=*/ false ,
6776
+ /* RequireActualConstructor=*/ false ,
6779
6777
/* SecondStepOfCopyInit=*/ true )) {
6780
6778
case OR_Success:
6781
6779
break ;
@@ -6921,6 +6919,7 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
6921
6919
S, Loc, CurInitExpr, CandidateSet, CurInitExpr->getType (), Ctors, Best,
6922
6920
/* CopyInitializing=*/ false , /* AllowExplicit=*/ true ,
6923
6921
/* OnlyListConstructors=*/ false , /* IsListInit=*/ false ,
6922
+ /* RequireActualConstructor=*/ false ,
6924
6923
/* SecondStepOfCopyInit=*/ true );
6925
6924
6926
6925
PartialDiagnostic Diag = S.PDiag (diag::warn_cxx98_compat_temp_copy)
0 commit comments