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
- boolcheckUnsafeAccess(Scope*sc, Expressione, boolreadonly, boolprintmsg);
- Check for unsafe access in @safe code:- read overlapped pointers
- write misaligned pointers
- write overlapped storage classes
 Parameters:Scope* scscope Expression eexpression to check bool readonlyif access is read-only bool printmsgprint 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:Expression eexpression to be cast Type tfromtype of e Type ttotype to cast e to string msgreason 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 .funcptrParameters:Scope* sccontext Expression eexpression for error messages Identifier idptr or funcptr int flagDotExpFlag 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 whenfdwas just inferred to be @system ORfdwas @safe and an tried something unsafe.Parameters:FuncDeclaration fdfunction we're gonna rat on bool gagsuppress error message (used in escape.d) Loc loclocation 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:FuncDeclaration fdthe 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:FuncDeclaration fdcaller FuncDeclaration ffunction 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 @systemParameters:Scope* scscope that the unsafe statement / expression is in bool gagsurpress error message (used in escape.d) Loc loclocation 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...);
- Like setUnsafe, but for safety errors still behind preview switchesGiven 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 as setUnsafe
- 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 FeatureState fsfeature state from the preview flag bool gagsurpress error message Loc loclocation of error const(char)* formatprintf-style format string RootObject[] argsarguments 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 Mon Mar 31 10:28:01 2025