[Issue 12941] Everything should be @unsafe by default, and explicitly vetted (and documented) as @safe

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jun 19 10:30:05 PDT 2014


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

--- Comment #3 from hsteoh at quickfur.ath.cx ---
Hmm, nobody seems interested to add anything here, so I'll start.

The empty statement is @safe, so by extension, an empty function is @safe.

Therefore, invoking a @safe function is also @safe. So, function that (only)
calls @safe functions (and does nothing else), is also @safe.

Expressions using built-in types without indirection are @safe. (Right?)
Returning by-value types is also @safe.

All declarations without initializers are @safe, regardless of the type of the
declared symbol(s). Declarations with initializers are @safe provided the
initializer expression is @safe.

Control-flow constructs (if, else, for, foreach, do, while, goto, etc.) are all
@safe, provided their constituent elements are @safe. E.g., a for-loop is @safe
as long as the initializer, loop condition, loop increment, and loop body, are
all @safe. Same thing goes for compound statements: a compound statment is
@safe if all constituent statements are @safe.

These should cover the basics. Anything else? Once all basic constructs are
covered then we can look at cases that directly involve memory safety, like
references, pointers, slices, etc..

--


More information about the Digitalmars-d-bugs mailing list