Bug 21681 – Can't deduce recursive template function attributes
Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-03-06T05:36:12Z
Last change time
2024-08-27T11:07:12Z
Assigned to
No Owner
Creator
Илья Ярошенко
Comments
Comment #0 by ilyayaroshenko — 2021-03-06T05:36:12Z
Example:
void foo(S)(ref S s, int a)
{
if (--a)
bar(s, a);
s.m();
}
void bar(S)(ref S s, int a)
{
if (--a)
foo(s, a);
s.m();
}
struct S
{
int s;
void m() @safe pure nothrow @nogc
{
s++;
}
}
void main() @safe pure nothrow @nogc
{
S s;
bar(s, 10);
}
================
> rdmd playground.d
onlineapp.d(27): Error: pure function D main cannot call impure function onlineapp.bar!(S).bar
onlineapp.d(27): Error: @safe function D main cannot call @system function onlineapp.bar!(S).bar
onlineapp.d(8): onlineapp.bar!(S).bar is declared here
onlineapp.d(27): Error: @nogc function D main cannot call non-@nogc function onlineapp.bar!(S).bar
onlineapp.d(27): Error: function onlineapp.bar!(S).bar is not nothrow
onlineapp.d(24): Error: nothrow function D main may throw
Comment #1 by ilyayaroshenko — 2021-03-06T05:58:35Z
Reduced example:
void foo()(int a)
{
if (--a)
bar(a);
}
void bar()(int a)
{
if (--a)
foo(a);
}
void main() @safe pure nothrow @nogc
{
bar(10);
}
==============
onlineapp.d(15): Error: pure function D main cannot call impure function onlineapp.bar!().bar
onlineapp.d(15): Error: @safe function D main cannot call @system function onlineapp.bar!().bar
onlineapp.d(7): onlineapp.bar!().bar is declared here
onlineapp.d(15): Error: @nogc function D main cannot call non-@nogc function onlineapp.bar!().bar
onlineapp.d(15): Error: function onlineapp.bar!().bar is not nothrow
onlineapp.d(13): Error: nothrow function D main may throw
Comment #2 by dkorpel — 2024-08-27T11:07:12Z
*** This issue has been marked as a duplicate of issue 7205 ***