Bug 5105 – Member function template cannot be synchronized

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-23T00:53:00Z
Last change time
2014-03-12T13:24:21Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
rsinfu
Depends on
5504

Comments

Comment #0 by rsinfu — 2010-10-23T00:53:54Z
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 --------------------
Comment #1 by clugdbug — 2011-01-29T13:01:56Z
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.
Comment #2 by clugdbug — 2011-02-06T13:34:26Z
Comment #3 by crunchengine — 2014-03-09T07:55:32Z
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)
Comment #4 by crunchengine — 2014-03-12T13:24:21Z
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); }