www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22818] New: typesafe variadic function parameter of type

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

          Issue ID: 22818
           Summary: typesafe variadic function parameter of type class
                    should be scope
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

https://dlang.org/spec/function.html#typesafe_variadic_functions

Class objects can be allocated on the stack, so a typesafe variadic class
parameter should automatically be scope.

   safe:

  class C { int x; }

  ref int g(scope C c ...) {
    return c.x;
  }

correctly issues error: scope variable `c` may not be returned

but,

  ref int g(scope C c ...) {
    return c.x;
  }

erroneously compiles without error.

--
Feb 23 2022