5105 – Member function template cannot be synchronized

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5105 - Member function template cannot be synchronized
Summary: Member function template cannot be synchronized
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on: 5504
Blocks:
Show dependency tree / graph
Reported: 2010年10月23日 00:53 UTC by Shin Fujishiro
Modified: 2014年03月12日 13:24 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010年10月23日 00:53:54 UTC
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 Don 2011年01月29日 13:01:56 UTC
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 3 Adrien Pensart 2014年03月09日 07:55:32 UTC
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 Adrien Pensart 2014年03月12日 13:24:21 UTC
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 によって変換されたページ (->オリジナル) /