Report a bugIf you spot a problem with this page, click here to create a Bugzilla issue.
Improve this pageQuickly 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 usinga local clone.
dmd.safe
Checks whether member access or array casting is allowed in@safe code.
bool
checkUnsafeAccess(Scope*
sc, Expression
e, bool
readonly, bool
printmsg);
Check for unsafe access in @safe code:
- read overlapped pointers
- write misaligned pointers
- write overlapped storage classes
Print error if unsafe.
Parameters:Scope*sc | scope |
Expressione | expression to check |
boolreadonly | if access is read-only |
boolprintmsg | print error message if true |
bool
isSafeCast(Expression
e, Type
tfrom, Type
tto, ref string
msg);
Determine if it is @safe to cast e from tfrom to tto.
Parameters:Expressione | expression to be cast |
Typetfrom | type of e |
Typetto | type to cast e to |
stringmsg | reason why cast is unsafe or deprecated |
Returns:true if @safe or deprecated
bool
checkUnsafeDotExp(Scope*
sc, Expression
e, Identifier
id, int
flag);
Check for unsafe use of.ptr or.funcptr
Parameters:Scope*sc | context |
Expressione | expression for error messages |
Identifierid | ptr orfuncptr |
intflag | DotExpFlag |
bool
isSaferD(FuncDeclaration
fd);
Safer D adds safety checks to functions with the default trust setting.
void
reportSafeError(FuncDeclaration
fd, bool
gag, Loc
loc, const(char)*
format, RootObject[]
args...);
Report safety violation for functionfd, 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:FuncDeclarationfd | function we are gonna rat on |
boolgag | suppress error message (used in escape.d) |
Locloc | location of error |
const(char)*format | printf-style format string |
RootObject[]args | arguments for %s format specifier |
bool
setFunctionToUnsafe(FuncDeclaration
fd);
Function is doing something unsafe. If inference is in process, commit the function to be @system.
Parameters:FuncDeclarationfd | 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(FuncDeclaration
fd, FuncDeclaration
f);
The function is calling@system functionf, so mark it as unsafe.
Parameters:FuncDeclarationfd | caller |
FuncDeclarationf | function being called (needed for diagnostic of inferred functions) |
Returns:whether there's a safe error
bool
setUnsafe(Scope*
sc, bool
gag, Loc
loc, const(char)*
format, RootObject[]
args...);
A statement / expression in this scope is not@safe, so mark the enclosing function as@system
Parameters:Scope*sc | scope that the unsafe statement / expression is in |
boolgag | surpress error message (used in escape.d) |
Locloc | 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, FeatureState
fs, bool
gag, Loc
loc, const(char)*
format, RootObject[]
args...);
LikesetUnsafe, but for safety errors still behind preview switches
Given a
FeatureStatefs, 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 assetUnsafe - 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 |
FeatureStatefs | feature state from the preview flag |
boolgag | surpress error message |
Locloc | 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