D issues are now
tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Summary: |
Member function template cannot be synchronized |
Product: |
D
|
Reporter: |
Shin Fujishiro <rsinfu> |
Component: |
dmd | Assignee: |
No Owner <nobody> |
Status: |
RESOLVED
FIXED
|
Severity: |
regression
|
CC: |
clugdbug, crunchengine
|
Priority: |
P2
|
Keywords: |
patch, rejects-valid |
Version: |
D2 |
Hardware: |
All |
OS: |
All |
Issue Depends on: |
5504
|
Issue Blocks: |
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.
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);
}