D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22818 - typesafe variadic function parameter of type class should be scope
Summary: typesafe variadic function parameter of type class should be scope
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, safe
Depends on:
Blocks:
 
Reported: 2022-02-23 08:56 UTC by Walter Bright
Modified: 2022-02-24 10:11 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2022-02-23 08:56:07 UTC
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.
Comment 1 Walter Bright 2022-02-24 02:45:40 UTC
Oops, the second example should be:

>   ref int g(C c ...) {
>     return c.x;
>   }
Comment 2 Dlang Bot 2022-02-24 02:46:49 UTC
@WalterBright created dlang/dmd pull request #13714 "fix Issue 22818 - typesafe variadic function parameter of type class …" fixing this issue:

- fix Issue 22818 - typesafe variadic function parameter of type class should be scope

https://github.com/dlang/dmd/pull/13714
Comment 3 Dlang Bot 2022-02-24 10:11:21 UTC
dlang/dmd pull request #13714 "fix Issue 22818 - typesafe variadic function parameter of type class …" was merged into master:

- c6fba23e8ddeddb7ebe8f83fd410283f35e24ede by Walter Bright:
  fix Issue 22818 - typesafe variadic function parameter of type class should be scope

https://github.com/dlang/dmd/pull/13714