Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

dmd.safe

Checks whether member access or array casting is allowed in@safe code.

SpecificationFunction Safety

Authors:
Walter Bright
License:
Boost License 1.0

Sourcesafe.d

Documentationhttps://dlang.org/phobos/dmd_safe.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/safe.d

boolcheckUnsafeAccess(Scope*sc, Expressione, boolreadonly, boolprintmsg);
Check for unsafe access in @safe code:
  1. read overlapped pointers
  2. write misaligned pointers
  3. write overlapped storage classes
Print error if unsafe.
Parameters:
Scope*scscope
Expressioneexpression to check
boolreadonlyif access is read-only
boolprintmsgprint error message if true
Returns:
true if error
boolisSafeCast(Expressione, Typetfrom, Typetto, ref stringmsg);
Determine if it is @safe to cast e from tfrom to tto.
Parameters:
Expressioneexpression to be cast
Typetfromtype of e
Typettotype to cast e to
stringmsgreason why cast is unsafe or deprecated
Returns:
true if @safe or deprecated
boolcheckUnsafeDotExp(Scope*sc, Expressione, Identifierid, intflag);
Check for unsafe use of.ptr or.funcptr
Parameters:
Scope*sccontext
Expressioneexpression for error messages
Identifieridptr orfuncptr
intflagDotExpFlag
Returns:
true if error
boolisSaferD(FuncDeclarationfd);
Safer D adds safety checks to functions with the default trust setting.
voidreportSafeError(FuncDeclarationfd, boolgag, Locloc, 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:
FuncDeclarationfdfunction we are gonna rat on
boolgagsuppress error message (used in escape.d)
Locloclocation of error
const(char)*formatprintf-style format string
RootObject[]argsarguments for %s format specifier
boolsetFunctionToUnsafe(FuncDeclarationfd);
Function is doing something unsafe. If inference is in process, commit the function to be @system.
Parameters:
FuncDeclarationfdthe naughty function
Returns:
true if this is a safe function and so an error OR is inferred to be @system, false otherwise.
boolsetUnsafeCall(FuncDeclarationfd, FuncDeclarationf);
The function is calling@system functionf, so mark it as unsafe.
Parameters:
FuncDeclarationfdcaller
FuncDeclarationffunction being called (needed for diagnostic of inferred functions)
Returns:
whether there's a safe error
boolsetUnsafe(Scope*sc, boolgag, Locloc, const(char)*format, RootObject[]args...);
A statement / expression in this scope is not@safe, so mark the enclosing function as@system
Parameters:
Scope*scscope that the unsafe statement / expression is in
boolgagsurpress error message (used in escape.d)
Locloclocation of error
const(char)*formatprintf-style format string
RootObject[]argsarguments for format string
Returns:
whether there is a safe error
boolsetUnsafePreview(Scope*sc, FeatureStatefs, boolgag, Locloc, const(char)*format, RootObject[]args...);
LikesetUnsafe, but for safety errors still behind preview switches
Given aFeatureStatefs, 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*scused to find affected function/variable, and for checking whether we are in a deprecated / speculative scope
FeatureStatefsfeature state from the preview flag
boolgagsurpress error message
Locloclocation of error
const(char)*formatprintf-style format string
RootObject[]argsarguments for format string
Returns:
whether an actual safe error (not deprecation) occured
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 00:05:03 2026

[8]ページ先頭

©2009-2026 Movatter.jp