www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20898] New: order dependency in evaluating pragma(inline) for

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 puremagic.com
          Reporter: bugzilla 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.)

--
Jun 05