Thread overview
pragma(inline) doesnt work on local functions : DMD
Sep 02
claptrap
Sep 03
RazvanN
Sep 03
Johan
September 02

Seems like an oversight?

int Foo()
{
    pragma(inline,true)
    int GetFoo() { return 42; }
    return GetFoo();
}

GetFoo isn't inlined, but inlines OK if you pass -inline to the compiler

Also inlines OK if you define GetFoo outside of Foo

September 03

On Monday, 2 September 2024 at 22:16:53 UTC, claptrap wrote:

>

Seems like an oversight?

int Foo()
{
    pragma(inline,true)
    int GetFoo() { return 42; }
    return GetFoo();
}

GetFoo isn't inlined, but inlines OK if you pass -inline to the compiler

Also inlines OK if you define GetFoo outside of Foo

As per the docs [1]: "If at the declaration level, it affects the functions declared in the block it controls. If inside a function, it affects the function it is enclosed by". So you probably just need to put the pragma(inline) in GetFoo.

RazvanN

[1] https://dlang.org/spec/pragma.html#inline

September 03

On Tuesday, 3 September 2024 at 14:05:40 UTC, RazvanN wrote:

>

On Monday, 2 September 2024 at 22:16:53 UTC, claptrap wrote:

>

Seems like an oversight?

int Foo()
{
    pragma(inline,true)
    int GetFoo() { return 42; }
    return GetFoo();
}

GetFoo isn't inlined, but inlines OK if you pass -inline to the compiler

Also inlines OK if you define GetFoo outside of Foo

As per the docs [1]: "If at the declaration level, it affects the functions declared in the block it controls. If inside a function, it affects the function it is enclosed by". So you probably just need to put the pragma(inline) in GetFoo.

I consider this a bug. Note there is no semicolon after the pragma, so it is at declaration level (declaration of GetFoo).
In the test case, current frontend applies the pragma to Foo which I think is wrong (because no semicolon after the pragma).

-Johan

September 03
On 9/3/2024 10:16 AM, Johan wrote:
> I consider this a bug.

Please submit bugs to bugzilla!