1 
test1()2 void test1()
3 {
4     static struct Foo1
5     {
6     }
7 
8     Foo1 foo1;
9     Foo1 foo1_2 = Foo1();       // literal syntax
10 
11     static assert(!__traits(compiles, foo1()));
12 }
13 
14 /**************************************/
15 
test2()16 void test2()
17 {
18     static struct Foo2
19     {
20         this(int n){}
21     }
22 
23     Foo2 foo2;
24     Foo2 foo2_2 = Foo2(1);      // user ctor call
25     Foo2 foo2_3 = Foo2();       // literal syntax
26 
27     static assert(!__traits(compiles, foo2(1)));
28     static assert(!__traits(compiles, foo2()));
29 }
30 
31 /**************************************/
32 
test2a()33 void test2a()
34 {
35     static struct Foo2a // alternation of Foo2
36     {
37         static Foo2a opCall(int n){ Foo2a foo2a; return foo2a; }
38     }
39 
40     Foo2a foo2a;
41     Foo2a foo2a_3 = Foo2a(1);                       // static opCall
42     static assert(!__traits(compiles, Foo2a()));    // static opCall hides literal syntax.
43 
44     foo2a(1);                                       // static opCall from instance
45     static assert(!__traits(compiles, foo2a()));
46 }
47 
48 /**************************************/
49 
test2c()50 void test2c()
51 {
52     static struct Foo2c // conflict version
53     {
54         this(int n){}
55         static Foo2c opCall(int n, int m){ Foo2c foo2c; return foo2c; }
56     }
57 
58     Foo2c foo2c;
59     Foo2c foo2c_2 = Foo2c(1);                       // user ctor call
60     static assert(!__traits(compiles, Foo2c(1,2))); // user ctor hides static opCall.
61     Foo2c foo2c_3 = Foo2c();                        // literal syntax
62 
63     static assert(!__traits(compiles, foo2c(1)));
64     foo2c(1,2);                                     // static opCall from instance
65     static assert(!__traits(compiles, foo2c()));
66 }
67 
68 /**************************************/
69 
test3()70 void test3()
71 {
72     static struct Foo3
73     {
74         this(int n){}
75         int opCall(int n){ return 0; }
76     }
77 
78     Foo3 foo3;
79     Foo3 foo3_2 = Foo3();                           // literal syntax (default construction)
80     Foo3 foo3_3 = Foo3(1);                          // user ctor call
81 
82     assert(foo3(1) == 0);                           // instance opCall
83     static assert(!__traits(compiles, foo3()));
84 }
85 
86 /**************************************/
87 
test3c()88 void test3c()
89 {
90     static struct Foo3c
91     {
92         this(int n){}
93         static Foo3c opCall(int n, int m){ Foo3c foo3c; return foo3c; }
94         int opCall(int n){ return 0; }
95     }
96 
97     Foo3c foo3c;
98     Foo3c foo3c_2 = Foo3c();                        // literal syntax (default construction)
99     Foo3c foo3c_3 = Foo3c(1);                       // user ctor call
100     static assert(!__traits(compiles, Foo3c(1,2))); // user ctor hides static opCall
101 
102     assert(foo3c(1,2) == Foo3c.init);               // static opCall from instance
103     assert(foo3c(1) == 0);                          // instance opCall
104     static assert(!__traits(compiles, foo3c()));
105 }
106 
107 /**************************************/
108 
test4()109 void test4()
110 {
111     static struct Foo4
112     {
113         static Foo4 opCall(int n, int m){ Foo4 foo4; return foo4; }
114         int opCall(int n){ return 0; }
115     }
116 
117     Foo4 foo4;
118     Foo4 foo4_4 = Foo4(1,2);                        // static opCall
119     static assert(!__traits(compiles, Foo4(1)));
120     static assert(!__traits(compiles, Foo4()));     // static opCall without constructor hides literal syntax
121 
122     assert(foo4(1,2) == Foo4.init);                 // static opCall from instance
123     assert(foo4(1) == 0);                           // instance opCall
124     static assert(!__traits(compiles, foo4()));
125 }
126 
127 /**************************************/
128 // 12070
129 
test12070()130 void test12070()
131 {
132     static string result;
133 
134     struct S
135     {
136         this(T...)(T)
137         {
138             result ~= "c" ~ cast(char)('0' + T.length);
139         }
140 
141         void opCall(A...)(A)
142         {
143             result ~= "x" ~ cast(char)('0' + A.length);
144         }
145     }
146 
147     auto s0 = S();
148     s0();
149     s0(1);
150     s0(1, 2);
151     assert(result == "x0x1x2");
152 
153     result = null;
154 
155     auto s1 = S(1);
156     s1();
157     s1('a');
158     s1('a', 'b');
159     assert(result == "c1x0x1x2");
160 }
161 
162 /**************************************/
163 // 12124
164 
165 struct S12124
166 {
thisS12124167     this(int) {}
opCallS12124168     S12124 opCall()() { static assert(0); }
169     // speculative opCall instantiation for diagnostic message should not cause false errors
170 }
171 
172 /**************************************/
173 
main()174 void main()
175 {
176     test1();
177     test2();
178     test2a();
179     test2c();
180     test3();
181     test3c();
182     test4();
183     test12070();
184 }
185