@@ -256,6 +256,10 @@ Return:
256
256
*/
257
257
bool checkHasBothRvalueAndCpCtor (StructDeclaration sd, CtorDeclaration ctor, TemplateInstance ti)
258
258
{
259
+ // printf("checkHasBothRvalueAndCpCtor() sd: %s ctor: %s ti: %s\n", sd.toChars(), ctor.toChars(), ti.toChars());
260
+ /* cannot use ctor.isMoveCtor because semantic pass may not have been run yet,
261
+ * so use isRvalueConstructor()
262
+ */
259
263
if (sd && sd.hasCopyCtor && isRvalueConstructor(sd, ctor))
260
264
{
261
265
.error(ctor.loc, " cannot define both an rvalue constructor and a copy constructor for `struct %s`" , sd.toChars());
@@ -280,6 +284,7 @@ bool checkHasBothRvalueAndCpCtor(StructDeclaration sd, CtorDeclaration ctor, Tem
280
284
*/
281
285
bool isRvalueConstructor (StructDeclaration sd, CtorDeclaration ctor)
282
286
{
287
+ // note commonality with setting isMoveCtor in the semantic code for CtorDeclaration
283
288
auto tf = ctor.type.isTypeFunction();
284
289
const dim = tf.parameterList.length;
285
290
if (dim == 1 || (dim > 1 && tf.parameterList[1 ].defaultArg))
@@ -306,6 +311,7 @@ bool isRvalueConstructor(StructDeclaration sd, CtorDeclaration ctor)
306
311
*/
307
312
Expression resolveAliasThis (Scope* sc, Expression e, bool gag = false , bool findOnly = false )
308
313
{
314
+ // printf("resolveAliasThis() %s\n", toChars(e));
309
315
import dmd.typesem : dotExp;
310
316
for (AggregateDeclaration ad = isAggregate(e.type); ad;)
311
317
{
@@ -2399,7 +2405,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
2399
2405
2400
2406
override void visit (CtorDeclaration ctd)
2401
2407
{
2402
- // printf("CtorDeclaration::semantic() %s\n", toChars());
2408
+ // printf("CtorDeclaration::semantic() %p % s\n", ctd, ctd. toChars());
2403
2409
if (ctd.semanticRun >= PASS .semanticdone)
2404
2410
return ;
2405
2411
if (ctd._scope)
@@ -2500,12 +2506,15 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
2500
2506
}
2501
2507
else if ((dim == 1 || (dim > 1 && tf.parameterList[1 ].defaultArg)))
2502
2508
{
2503
- // printf("tf: %s\n", tf. toChars());
2509
+ // printf("tf: %s\n", toChars(tf ));
2504
2510
auto param = tf.parameterList[0 ];
2505
- if (param.storageClass & STC .ref_ && param. type.mutableOf().unSharedOf() == sd.type.mutableOf().unSharedOf())
2511
+ if (param.type.mutableOf().unSharedOf() == sd.type.mutableOf().unSharedOf())
2506
2512
{
2507
- // printf("copy constructor\n");
2508
- ctd.isCpCtor = true ;
2513
+ // printf("copy constructor %p\n", ctd);
2514
+ if (param.storageClass & STC .ref_)
2515
+ ctd.isCpCtor = true ; // copy constructor
2516
+ else
2517
+ ctd.isMoveCtor = true ; // move constructor
2509
2518
}
2510
2519
}
2511
2520
}
@@ -2996,7 +3005,10 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
2996
3005
2997
3006
buildDtors(sd, sc2);
2998
3007
2999
- sd.hasCopyCtor = buildCopyCtor(sd, sc2);
3008
+ bool hasMoveCtor;
3009
+ sd.hasCopyCtor = buildCopyCtor(sd, sc2, hasMoveCtor);
3010
+ sd.hasMoveCtor = hasMoveCtor;
3011
+
3000
3012
sd.postblit = buildPostBlit(sd, sc2);
3001
3013
3002
3014
buildOpAssign(sd, sc2);
0 commit comments