[Issue 20898] New: order dependency in evaluating pragma(inline) for functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 6 03:12:01 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20898

          Issue ID: 20898
           Summary: order dependency in evaluating pragma(inline) for
                    functions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

If the pragma(inline) is present in the function body, the semantic analysis of
the function body must be done before the function is called in order for it to
be recognized:

  int test(int j) {
    void bar() { pragma(inline, true); ++j; }
    return foo(j);
  }

  int foo(int i) {
    pragma(inline, true);
    while (i)
        i = i * 2;
    return i + 1;
  }

This compiles successfully with -inline switch, even though foo() is called,
and is not inlined. If foo() is defined above test(), it will fail to compile.

The solution is to deprecate use of pragma(inline) inside of functions where
attributes cannot be inferred. (I.e. most freestanding functions.)

--


More information about the Digitalmars-d-bugs mailing list