www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - pragma(inline) doesnt work on local functions : DMD

reply claptrap <clap trap.com> writes:
Seems like an oversight?

```d
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
Sep 02
parent reply RazvanN <razvan.nitu1305 gmail.com> writes:
On Monday, 2 September 2024 at 22:16:53 UTC, claptrap wrote:
 Seems like an oversight?

 ```d
 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
Sep 03
parent reply Johan <j j.nl> writes:
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?

 ```d
 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
Sep 03
parent Walter Bright <newshound2 digitalmars.com> writes:
On 9/3/2024 10:16 AM, Johan wrote:
 I consider this a bug.
Please submit bugs to bugzilla!
Sep 03