April 27, 2021

On Tuesday, 27 April 2021 at 09:37:42 UTC, MoonlightSentinel wrote:

>

DMD doesn't catch the error even when making tempCString and browse @safe (using appropriate @trusted lambdas, ...):

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

What does scope mean on a function declaration?

April 27, 2021

On Tuesday, 27 April 2021 at 10:53:10 UTC, Vladimir Panteleev wrote:

>

What does scope mean on a function declaration?

It applies to the this pointer for member methods, just like return.
(Allthough scope is implicitly applied for structs IIRC)

April 27, 2021

On Tuesday, 27 April 2021 at 11:33:45 UTC, MoonlightSentinel wrote:

>

On Tuesday, 27 April 2021 at 10:53:10 UTC, Vladimir Panteleev wrote:

>

What does scope mean on a function declaration?

It applies to the this pointer for member methods, just like return.
(Allthough scope is implicitly applied for structs IIRC)

If I had a magic wand I would make the this pointer explicit, now that we annotate it often.

April 27, 2021

On Monday, 26 April 2021 at 11:44:26 UTC, Dominikus Dittes Scherkl wrote:

> >

Unfortunately, Phobos got bitten by exactly the same use-after-free bug as the article showcases:

https://github.com/dlang/phobos/pull/7988/commits/08927149ccbb3a20fb7e97687065fe66a33e2cb8

Bug was in @trusted code.

April 27, 2021

On Tuesday, 27 April 2021 at 11:33:45 UTC, MoonlightSentinel wrote:

>

On Tuesday, 27 April 2021 at 10:53:10 UTC, Vladimir Panteleev wrote:

>

What does scope mean on a function declaration?

It applies to the this pointer for member methods, just like return.

Aah, so it makes scope with classes great again. I keep getting surprised by how awesome DIP1000 is.

>

(Allthough scope is implicitly applied for structs IIRC)

That's interesting, because it seems to be required in the bug you filed.

April 27, 2021
On Monday, 26 April 2021 at 01:28:35 UTC, Walter Bright wrote:
> https://alexgaynor.net/2019/apr/21/modern-c++-wont-save-us/
>
> Lists some perfectly reasonable code in Modern C++ style that has hidden memory safety bugs.

Not at all reasonable to take a borrowing reference from a temporary... string_view is not owning.

C++ does not use the compiler to check for memory safety issues. Ownership in C++ is a library concept, not a language concept.

C++ is more geared towards using linters for such things. Or rather, that is what is being suggested by providing annotations for owning/non-wning references.

April 27, 2021
On Monday, 26 April 2021 at 12:05:48 UTC, Calvin P wrote:
> On Monday, 26 April 2021 at 01:28:35 UTC, Walter Bright wrote:
>> https://alexgaynor.net/2019/apr/21/modern-c++-wont-save-us/
>>
>> Lists some perfectly reasonable code in Modern C++ style that has hidden memory safety bugs.
>
> Rust used for kernel/browser/database/UI, D also king able to work but not work good(no product or big projects).
>
>
> Rust replace c++ jobs, go replace java jobs.  D need better long-term strategy.

it is sad but such message is put with regularity years after years.
It is fun to see the rust born by reading old message in this forum.

About the long-term strategy, to my understanding they works on D language and expect that someone will do the killer application «à la» ruby on rails or python datascience or java hadoop.

But the problem is still here, years after years.

Maybe a day …
April 27, 2021
On Monday, 26 April 2021 at 12:05:48 UTC, Calvin P wrote:
> On Monday, 26 April 2021 at 01:28:35 UTC, Walter Bright wrote:
>> https://alexgaynor.net/2019/apr/21/modern-c++-wont-save-us/
>>
>> Lists some perfectly reasonable code in Modern C++ style that has hidden memory safety bugs.
>
> Rust used for kernel/browser/database/UI, D also king able to work but not work good(no product or big projects).
>
>
> Rust replace c++ jobs, go replace java jobs.  D need better long-term strategy.

For me, D replace Python for data crutching.
April 27, 2021
On 4/27/2021 4:33 AM, MoonlightSentinel wrote:
> On Tuesday, 27 April 2021 at 10:53:10 UTC, Vladimir Panteleev wrote:
>> What does `scope` mean on a function declaration?
> 
> It applies to the `this` pointer for member methods, just like `return`.
> (Allthough `scope` is implicitly applied for structs IIRC)

This isn't quite right. For structs,

    struct S {
        int* ptr;
        int* hello() scope;
	static int* betty(scope ref S s);
    }

The `this` reference is passed by `ref`. So, `hello` is exactly equivalent to `betty`.

The `ref` already prevents returning the address of a struct. The `scope` prevents the return of `s.ptr` and equivalently `this.ptr`.

This is likely why, in the bug report, the `ptr` field was necessary.

As always, when confused about this, rewrite the code in terms of simple ref's and pointers.
April 28, 2021
On Tuesday, 27 April 2021 at 23:38:14 UTC, Walter Bright wrote:
>
> As always, when confused about this, rewrite the code in terms of simple ref's and pointers.

I think a large part of the confusion here stems from the fact that `scope ref T` behaves very differently from `scope T*`, even though `ref T` and `T*` are the same "under the hood."

    @safe:
    static int* betty(scope ref S s) { return s.ptr; } // Error
    static int* veronica(scope S* s) { return s.ptr; } // Ok

Unfortunately, there is no documentation of this distinction in the language spec (or anywhere else, as far as I know), so the only way anyone can learn about it is through trial and error.