| 1 |
// EXTRA_FILES: imports/link14541traits.d |
| 2 |
import imports.link14541traits; |
| 3 |
|
| 4 |
void main() |
| 5 |
{ |
| 6 |
Tuple!(int, int) result; |
| 7 |
|
| 8 |
alias T = typeof(result); |
| 9 |
static assert(hasElaborateAssign!T); |
| 10 |
// hasElaborateAssign!(Tuple(int, int)): |
| 11 |
// 1. instantiates Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Rvalue] |
| 12 |
// 2. instantiates swap!(Tuple!(int, int)) |
| 13 |
// 3. instantiates hasElaborateAssign!(Tuple!(int, int)) |
| 14 |
// --> forward reference error |
| 15 |
// --> swap!(Tuple!(int, int)) fails to instantiate |
| 16 |
// --> Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = rvalue] fails to instantiate |
| 17 |
// 4. instantiates Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Lvalue] |
| 18 |
// --> succeeds |
| 19 |
// hasElaborateAssign!(Tuple(int, int)) succeeds to instantiate (result is 'true') |
| 20 |
|
| 21 |
// Instantiates Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Rvalue], but |
| 22 |
// it's already done in gagged context, so this is made an error reproduction instantiation. |
| 23 |
// But, the forward reference of hasElaborateAssign!(Tuple(int, int)) is already resolved, so |
| 24 |
// the instantiation will succeeds. |
| 25 |
result = Tuple!(int, int)(0, 0); // --> 1st error reproduction instantiation |
| 26 |
result = Tuple!(int, int)(0, 0); // --> 2nd error reproduction instantiation |
| 27 |
|
| 28 |
// The two error reproduction instantiations generate the function: |
| 29 |
// Tuple!(int, int).opAssign!(Tuple!(int, int)) [auto ref = Rvalue] |
| 30 |
// twice, then it will cause duplicate COMDAT error in Win64 platform. |
| 31 |
} |
| 32 |
|
| 33 |
/+ |
| 34 |
The point is, if instantiated contexts are different, two instantiations may cause different result. |
| 35 |
|
| 36 |
- The 1st Tuple.opAssign instantiation is invoked from hasElaborateAssign template with gagging. |
| 37 |
So it has failed, because of the circular reference of hasElaborateAssign template.. |
| 38 |
|
| 39 |
- The 2nd Tuple.opAssign instantiation is invoked from main() without gagging. |
| 40 |
It does not have circular reference, so the instantiation should succeed. |
| 41 |
|
| 42 |
Therefore, the gagged failure should be overridden by the ungagged success. |
| 43 |
+/ |