[Issue 18265] `scope` storage class w/ -dip1000 and `scope` type modifier behavior inconsistent

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 19 23:31:25 UTC 2018


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

Carsten Blüggel <chilli at posteo.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chilli at posteo.net

--- Comment #2 from Carsten Blüggel <chilli at posteo.net> ---
For all the following, add stdout.flush(); to A's destructor.

IIRC, the scope _attribute_ in Your 1. program version declares a class, that
shall be allocated on the stack. It's deprecated, and by it's nature, an
already destroyed object of that type can't be returned from a function,
detected by the compiler - knowing that A is a scope class - in line 10
already.
https://dlang.org/spec/class.html#auto

Your 2. program version is more interesting: First, change scope to auto,
compile  without -dip1000, and the program prints as expected:
entering fun()
A.this()
leaving fun()
A.method()
A.~this()

Back to Your 'original' 2. program version (scope a), still without -dip1000,
You have an undefined behavior program as per Your comments, undetected by the
compiler, it prints and then segfaults:
entering fun()
A.this()
leaving fun()
A.~this()

Thus the difference auto<->scope here is that scope forces A's destructor when
a's lifetime ends, as per Your comment line.

Now with -dip1000 enabled, additional checks are applied and compiling already
fails, but the error occurs in line 16. An A may be returned by fun(), but not
one assigned to a scope variable.

Thus IMO everything is fine here as per language rules and DIP1000, except that
acc. to DIP1000, the additional checks should kick in only for @safe attributed
functions.

I suggest to change the issue text accordingly.

--


More information about the Digitalmars-d-bugs mailing list