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