123
123
// �8.5.14 initialization
124
124
CCConvSeq *CCConversions::implicitConversions (CTypeInfo *ptype,
125
125
CTypeInfo *atype, CTree *arg_expr, CTree *base, bool user_def) {
126
if (! atype || ! ptype)
126
129
// argument passing is a copy-initialization
127
130
if (atype->isAddress ())
128
131
atype = atype->BaseType ();
159
162
if (param->isPointer () &&
160
163
(param->BaseType ()->UnqualType ()->is_void () ||
161
164
(arg_expr->NodeName () == CT_String::NodeId () &&
162
param->BaseType ()->UnqualType ()->is_char ()) ||
165
param->BaseType ()->UnqualType ()->is_char ()) ||
163
166
(arg_expr->NodeName () == CT_WideString::NodeId () &&
164
param->BaseType ()->UnqualType ()->is_wchar_t ()))) {
167
param->BaseType ()->UnqualType ()->is_wchar_t ()))) {
165
168
// convert to "pointer to char" resp. to "pointer to wchar_t"
166
169
seq->addConversion (new CCArrayToPointerConv (param, arg, arg_expr, base));
167
170
arg = arg->BaseType ()->UnqualType ();
309
312
seq = new CCUserDefinedConvSeq;
310
313
// 1. initial standard conversion sequence
311
314
seq->addConversion (new CCDerivedToBaseConv (param, arg, arg_expr, base));
312
// 2. user-defined conversion
315
// 2. user-defined conversion
313
316
seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
314
// 3. second standard conversion sequence
315
seq2 = new CCStandardConvSeq;
317
// 3. second standard conversion sequence
318
seq2 = new CCStandardConvSeq;
316
319
seq2->addConversion (new CCIdentityConv (param, arg, arg_expr, base));
317
seq->addConversion (seq2);
320
seq->addConversion (seq2);
319
322
// �13.3.1.4 initialization of class type with a (non-)class type
322
325
// candidates are conversion functions of c1 and its base
323
// classes that are visible in c1 and yield a type whose
324
// cv-unqualified version is the same type as c2 or is a
325
// derived class thereof (including functions returning
326
// "reference to c2" => treated as "c2")
327
ovl.collectConvFunctions (c1);
326
// classes that are visible in c1 and yield a type whose
327
// cv-unqualified version is the same type as c2 or is a
328
// derived class thereof (including functions returning
329
// "reference to c2" => treated as "c2")
330
ovl.collectConvFunctions (c1);
328
331
ovl.ObjectType (arg);
329
for (unsigned i = ovl.Candidates (); i > 0; i--) {
330
ctype = ovl.Candidate (i-1)->Function ()->ConversionType ();
331
if (! (*param->UnqualType () == *ctype->VirtualType () ||
332
(ctype->isClass () && baseClass (param, ctype))))
333
ovl.removeCandidate (i-1);
332
for (unsigned i = ovl.Candidates (); i > 0; i--) {
333
ctype = ovl.Candidate (i-1)->Function ()->ConversionType ();
334
if (! (*param->UnqualType () == *ctype->VirtualType () ||
335
(ctype->isClass () && baseClass (param, ctype))))
336
ovl.removeCandidate (i-1);
336
339
// candidates are converting constructors of c2
337
340
ovl.collectConstructors (c2);
340
343
if (isValidConversion (arg_expr, ptype, atype, ovl)) {
341
344
seq = new CCUserDefinedConvSeq;
342
345
// 1. initial standard conversion sequence (need not to
343
// be correct, not relevant to the algorithm at all)
346
// be correct, not relevant to the algorithm at all)
344
347
seq->addConversion (new CCIdentityConv (param, arg, arg_expr, base));
345
// 2. user-defined conversion
346
seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
347
// 3. second standard conversion sequence
348
seq2 = new CCStandardConvSeq;
348
// 2. user-defined conversion
349
seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
350
// 3. second standard conversion sequence
351
seq2 = new CCStandardConvSeq;
349
352
if (! ovl.Function ()->isConstructor () &&
350
baseClass (param, ovl.Function ()->ConversionType ()))
351
seq2->addConversion (new CCDerivedToBaseConv (param,
352
ovl.Function ()->ConversionType (), arg_expr, base));
353
baseClass (param, ovl.Function ()->ConversionType ()))
354
seq2->addConversion (new CCDerivedToBaseConv (param,
355
ovl.Function ()->ConversionType (), arg_expr, base));
354
357
seq2->addConversion (new CCIdentityConv (param,
355
ovl.Function ()->ConversionType (), arg_expr, base));
356
seq->addConversion (seq2);
358
ovl.Function ()->ConversionType (), arg_expr, base));
359
seq->addConversion (seq2);
436
439
ovl.collectConvFunctions (c);
437
440
for (unsigned i = ovl.Candidates (); i > 0; i--) {
438
441
ctype = ovl.Candidate (i-1)->Function ()->ConversionType ();
439
if (! ctype->isAddress () ||
440
! referenceCompatible (param, ctype->UnqualType ()->BaseType ()))
442
if (! ctype->isAddress () ||
443
! referenceCompatible (param, ctype->UnqualType ()->BaseType ()))
441
444
ovl.removeCandidate (i-1);
443
446
// select the best conversion function
450
453
// 2. user-defined conversion
451
454
seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
452
455
// 3. second standard conversion sequence
453
seq2 = new CCStandardConvSeq;
454
ctype = ovl.Function ()->ConversionType ();
456
seq2 = new CCStandardConvSeq;
457
ctype = ovl.Function ()->ConversionType ();
455
458
if (param->isClass () && ctype->isClass () && baseClass (param, ctype))
456
459
seq2->addConversion (new CCDerivedToBaseConv (param, ctype, arg_expr, base));
458
461
seq2->addConversion (new CCIdentityConv (param, ctype, arg_expr, base));
459
seq2->isReferenceBinding (true);
462
seq2->isReferenceBinding (true);
460
463
seq->addConversion (seq2);
469
472
referenceCompatible (param, arg)) {
470
473
seq = new CCStandardConvSeq;
471
474
// �13.3.3.1.4.2 not really clear which kind of conversion
472
// this is; is it right to distinguish like above?
475
// this is; is it right to distinguish like above?
473
476
if ((param->isClass () && arg->isClass () && baseClass (param, arg)))
474
477
seq->addConversion (new CCDerivedToBaseConv (param, arg, arg_expr, base));
476
479
seq->addConversion (new CCIdentityConv (param, arg, arg_expr, base));
477
480
// �13.3.3.1.4.2 reference not bound directly to argument expression
478
481
} else if (! (referenceRelated (param, arg) &&
479
! equalOrMoreQualified (param, arg))) {
482
! equalOrMoreQualified (param, arg))) {
480
483
// 1. create temporary of underlying parameter type
481
// 2. non-reference copy-initialization of temporary
484
// 2. non-reference copy-initialization of temporary
482
485
// 3. temporary is bound to reference
483
seq = implicitConversions (param, arg, arg_expr, base, user_def);
486
seq = implicitConversions (param, arg, arg_expr, base, user_def);
562
565
if ((p1->isMemberPointer () && ! p2->isMemberPointer ()) ||
563
566
(p2->isMemberPointer () && ! p1->isMemberPointer ()))
565
568
if (p1->isMemberPointer () &&
566
569
p1->TypeMemberPointer ()->Record () &&
567
p2->TypeMemberPointer ()->Record () &&
570
p2->TypeMemberPointer ()->Record () &&
568
571
! (*p1->TypeMemberPointer ()->Record () ==
569
572
*p2->TypeMemberPointer ()->Record ()))
572
575
p2 = p2->BaseType ();
573
576
if ((p1->UnqualType ()->isPointer () && ! p2->UnqualType ()->isPointer ()) ||
574
577
(p2->UnqualType ()->isPointer () && ! p1->UnqualType ()->isPointer ()))
577
580
if (p1->isQualified () && ! p2->isQualified ())
579
582
if (p1->isQualified ()) { // => p2->isQualified ()
580
583
if ((p1->isVolatile () && ! p2->isVolatile ()) ||
581
(p1->isConst () && ! p2->isConst ()))
583
if (((p1->isVolatile ()?1:0)+(p1->isConst ()?2:0)) !=
584
((p2->isVolatile ()?1:0)+(p2->isConst ()?2:0)) &&
584
(p1->isConst () && ! p2->isConst ()))
586
if (((p1->isVolatile ()?1:0)+(p1->isConst ()?2:0)) !=
587
((p2->isVolatile ()?1:0)+(p2->isConst ()?2:0)) &&
587
590
} else if (p2->isQualified () && ! all_const)
589
592
if (! p2->isQualified () || ! p2->isConst ())
672
675
c1 = seq1->Conversion (seq1->Conversions ()-1);
673
676
c2 = seq2->Conversion (seq2->Conversions ()-1);
674
677
if (c1->isQualificationConv () || c2->isQualificationConv ()) {
675
v1 = similarTypes (c1->ToType (), c2->ToType ());
676
v2 = similarTypes (c2->ToType (), c1->ToType ());
678
v1 = similarTypes (c2->ToType (), c1->ToType ()); // c1 similar to c2?
679
v2 = similarTypes (c1->ToType (), c2->ToType ()); // c2 similar to c1?
690
693
c2 = seq2->Conversion (0);
691
694
if (*c1->ToType ()->UnqualType () ==
692
695
*c2->ToType ()->UnqualType ()) {
693
v1 = equalOrMoreQualified (c1->ToType (), c2->ToType ());
694
v2 = equalOrMoreQualified (c2->ToType (), c1->ToType ());
696
v1 = equalOrMoreQualified (c1->ToType (), c2->ToType ());
697
v2 = equalOrMoreQualified (c2->ToType (), c1->ToType ());
701
704
} else if (seq1->isUserDefinedConvSeq ()) { // => seq2->isUserDefinedConvSeq ()
727
730
else if (c->isFloatingPointConv () || c->isIntegralConv () ||
728
731
c->isFloatingIntegralConv () || c->isPointerConv () ||
729
c->isPointerToMemberConv () || c->isBooleanConv () ||
730
c->isDerivedToBaseConv ())
732
c->isPointerToMemberConv () || c->isBooleanConv () ||
733
c->isDerivedToBaseConv ())
887
890
for (unsigned k = j; k < num_conv2; k++) {
888
891
// subsequence of seq2 is longer than subsequence of seq1
889
892
if ((num_conv2-k) > (num_conv1-i))
892
// subsequence of seq2 is shorter than subsequence of seq1
893
// so it cannot be a proper subsequence of seq2
895
// subsequence of seq2 is shorter than subsequence of seq1
896
// so it cannot be a proper subsequence of seq2
894
897
if ((num_conv2-k) < (num_conv1-i))
897
900
// compare seq1 with the remainder of seq2; must be equal
898
901
for (unsigned l = k; l < num_conv2; l++) {
899
902
c2 = seq2->Conversion (l);
901
// not the same type of conversion
902
if (c1->Id () != c2->Id ())
905
// same type of conversions; but also same parameter
906
// and argument types?
904
// not the same type of conversion
905
if (c1->Id () != c2->Id ())
908
// same type of conversions; but also same parameter
909
// and argument types?
907
910
if (*c1->FromType () != *c2->FromType () ||
908
*c1->ToType () != *c2->ToType ())
911
*c1->ToType () != *c2->ToType ())