Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
dmd.safe
Checks whether member access or array casting is allowed in @
safe
code.
Specification Function Safety
Authors:
License:
Source safe.d
Documentation https://dlang.org/phobos/dmd_safe.html
- bool
checkUnsafeAccess
(Scope*sc
, Expressione
, boolreadonly
, boolprintmsg
); - Check for unsafe access in @safe code:
- read overlapped pointers
- write misaligned pointers
- write overlapped storage classes
Parameters:Scope* sc
scope Expression e
expression to check bool readonly
if access is read-only bool printmsg
print error message if true Returns:true if error - bool
isSafeCast
(Expressione
, Typetfrom
, Typetto
, ref stringmsg
); - Determine if it is @safe to cast e from tfrom to tto.Parameters:
Expression e
expression to be cast Type tfrom
type of e Type tto
type to cast e to string msg
reason why cast is unsafe or deprecated Returns:true if @safe or deprecated - bool
checkUnsafeDotExp
(Scope*sc
, Expressione
, Identifierid
, intflag
); - Check for unsafe use of .ptr or .funcptrParameters:
Scope* sc
context Expression e
expression for error messages Identifier id
ptr or funcptr int flag
DotExpFlag Returns:true if error - bool
isSaferD
(FuncDeclarationfd
); - Safer D adds safety checks to functions with the default trust setting.
- void
reportSafeError
(FuncDeclarationfd
, boolgag
, Locloc
, const(char)*format
, RootObject[]args
...); - Report safety violation for function
fd
, or squirrel away error message in fd.safetyViolation if needed later. Call whenfd
was just inferred to be @system ORfd
was @safe and an tried something unsafe.Parameters:FuncDeclaration fd
function we're gonna rat on bool gag
suppress error message (used in escape.d) Loc loc
location of error const(char)* format
printf-style format string RootObject[] args
arguments for %s format specifier - bool
setFunctionToUnsafe
(FuncDeclarationfd
); - Function is doing something unsafe. If inference is in process, commit the function to be @system.Parameters:
FuncDeclaration fd
the naughty function Returns:true if this is a safe function and so an error OR is inferred to be @system, false otherwise. - bool
setUnsafeCall
(FuncDeclarationfd
, FuncDeclarationf
); - The function is calling @system function
f
, so mark it as unsafe.Parameters:FuncDeclaration fd
caller FuncDeclaration f
function being called (needed for diagnostic of inferred functions) Returns:whether there's a safe error - bool
setUnsafe
(Scope*sc
, boolgag
, Locloc
, const(char)*format
, RootObject[]args
...); - A statement / expression in this scope is not @safe, so mark the enclosing function as @systemParameters:
Scope* sc
scope that the unsafe statement / expression is in bool gag
surpress error message (used in escape.d) Loc loc
location of error const(char)* format
printf-style format string RootObject[] args
arguments for format string Returns:whether there is a safe error - bool
setUnsafePreview
(Scope*sc
, FeatureStatefs
, boolgag
, Locloc
, const(char)*format
, RootObject[]args
...); - Like setUnsafe, but for safety errors still behind preview switchesGiven a FeatureState
fs
, for example dip1000 / dip25 / systemVariables, the behavior changes based on the setting:- In case of -revert=
fs
, it does nothing. - In case of -preview=
fs
, it's the same as setUnsafe - By default, print a deprecation in @safe functions, or store an attribute violation in inferred functions.
Parameters:Scope* sc
used to find affected function/variable, and for checking whether we are in a deprecated / speculative scope FeatureState fs
feature state from the preview flag bool gag
surpress error message Loc loc
location of error const(char)* format
printf-style format string RootObject[] args
arguments for format string Returns:whether an actual safe error (not deprecation) occured - In case of -revert=
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Sun Apr 13 05:29:21 2025