DMD doesn't allow member function templates in synchronized class: -------------------- void main() { auto c = new C; c.foo(10); // (4) } synchronized shared class C { void foo(T)(T a) {} // (8) } -------------------- test.d(8): Error: function test.C.foo!(int).foo synchronized function foo must be a member of a class test.d(4): Error: template instance test.C.foo!(int) error instantiating -------------------- Patch against dmd r727: -------------------- --- src/func.c +++ src/func.c @@ -1551,7 +1551,8 @@ void FuncDeclaration::semantic3(Scope *sc) if (isSynchronized()) { /* Wrap the entire function body in a synchronized statement */ - ClassDeclaration *cd = parent->isClassDeclaration(); + AggregateDeclaration *ad = isThis(); + ClassDeclaration *cd = ad ? ad->isClassDeclaration() : NULL; if (cd) { #if TARGET_WINDOS --------------------
The patch works for a simplified test case: void main() { auto c = new C; c.foo(10); } synchronized class C { void foo(T)(T a) {} } Since DMD2.051, the original test case hits bug 5504.
Fixed: https://github.com/D-Programming-Language/dmd/commit/f25d6e98609259de5714b805f45f16880dd3031b
test_case_5105.d: void main() { auto c = new C; c.foo(10); } synchronized class C { void foo(T)(T a) {} } Fails again in DMD 2.065 or before : dmd test_case_5105.d test_case_5105.d(12): Error: template test_case_5105.C.foo cannot deduce function from argument types !()(int), candidates are: test_case_5105.d(3): test_case_5105.C.foo(T)(T a)
The test case was invalid, shared and synchronized keywords modifies the type of object when applied on class. synchronized class synchronized_C { void foo(T)(T a) {} } shared class shared_C { void foo(T)(T a) {} } synchronized shared class synchronized_shared_C { void foo(T)(T a) {} } void main() { auto c1 = new shared synchronized_C; c1.foo(10); auto c2 = new shared shared_C; c2.foo(10); auto c3 = new shared synchronized_shared_C; c3.foo(10); }
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル