Runtime Options#
These options affect the runtime behavior of programs compiled with gdc.
- -fall-instantiations#
Generate code for all template instantiations. The default template emission strategy is to not generate code for declarations that were either instantiated speculatively, such as from
__traits(compiles, ...), or that come from an imported module not being compiled.
- -fno-assert#
Turn off code generation for
assertcontracts.
- -fno-bounds-check#
Turns off array bounds checking for all functions, which can improve performance for code that uses arrays extensively. Note that this can result in unpredictable behavior if the code in question actually does violate array bounds constraints. It is safe to use this option if you are sure that your code never throws a
RangeError.
- -fbounds-check=value#
An alternative to
-fbounds-checkthat allows more control as to where bounds checking is turned on or off. The following values are supported:onTurns on array bounds checking for all functions.
safeonlyTurns on array bounds checking only for
@safefunctions.offTurns off array bounds checking completely.
- -fno-builtin#
Don’t recognize built-in functions unless they begin with the prefix
__builtin_. By default, the compiler will recognize when a function in thecore.stdcpackage is a built-in function.
- -fcheckaction#
This option controls what code is generated on an assertion, bounds check, or final switch failure. The following values are supported:
contextThrow an
AssertErrorwith extra context information.haltHalt the program execution.
throwThrow an
AssertError(the default).
- -fdebug=value#
Turn on compilation of conditional
debugcode into the program. The-fdebugoption itself sets the debug level to1, while-fdebug=enablesdebugcode that are identified by any of the following values:levelSets the debug level to
level, anydebugcode <=levelis compiled into the program.identTurns on compilation of any
debugcode identified byident.
- -fno-druntime#
Implements https://dlang.org/spec/betterc.html. Assumes that compilation targets an environment without a D runtime library.
This is equivalent to compiling with the following options:
gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
- -fextern-std=standard#
Sets the C++ name mangling compatibility to the version identified by
standard. The following values are supported:c++98,c++03Sets
__traits(getTargetInfo, "cppStd")to199711.c++11Sets
__traits(getTargetInfo, "cppStd")to201103.c++14Sets
__traits(getTargetInfo, "cppStd")to201402.c++17Sets
__traits(getTargetInfo, "cppStd")to201703. This is the default.c++20Sets
__traits(getTargetInfo, "cppStd")to202002.
- -fno-invariants#
Turns off code generation for class
invariantcontracts.
- -fmain#
Generates a default
main()function when compiling. This is useful when unittesting a library, as it enables running the unittests in a library without having to manually define an entry-point function. This option does nothing whenmainis already defined in user code.
- -fno-moduleinfo#
Turns off generation of the
ModuleInfoand related functions that would become unreferenced without it, which may allow linking to programs not written in D. Functions that are not be generated include module constructors and destructors (static thisandstatic ~this),unittestcode, andDSOregistry functions for dynamically linked code.
- -fonly=filename#
Tells the compiler to parse and run semantic analysis on all modules on the command line, but only generate code for the module specified by
filename.
- -fno-postconditions#
Turns off code generation for postcondition
outcontracts.
- -fno-preconditions#
Turns off code generation for precondition
incontracts.
- -fpreview=id#
Turns on an upcoming D language change identified by
id. The following values are supported:allTurns on all upcoming D language features.
dip1000Implements https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md (Scoped pointers).
dip1008Implements https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1008.md (Allow exceptions in
@nogccode).dip1021Implements https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md (Mutable function arguments).
dip25Implements https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md (Sealed references).
dtorfieldsTurns on generation for destructing fields of partially constructed objects.
fieldwiseTurns on generation of struct equality to use field-wise comparisons.
fixaliasthisImplements new lookup rules that check the current scope for
alias thisbefore searching in upper scopes.fiximmutableconvDisallows unsound immutable conversions that were formerly incorrectly permitted.
inImplements
inparameters to meanscope const [ref]and accepts rvalues.inclusiveincontractsImplements
incontracts of overridden methods to be a superset of parent contract.intpromoteImplements C-style integral promotion for unary
+,-and~expressions.nosharedaccessTurns off and disallows all access to shared memory objects.
rvaluerefparamImplements rvalue arguments to
refparameters.systemvariablesDisables access to variables marked
@systemfrom@safecode.
- -frelease#
Turns on compiling in release mode, which means not emitting runtime checks for contracts and asserts. Array bounds checking is not done for
@systemand@trustedfunctions, and assertion failures are undefined behavior.This is equivalent to compiling with the following options:
gdc -fno-assert -fbounds-check=safe -fno-invariants \ -fno-postconditions -fno-preconditions -fno-switch-errors
- -frevert=#
Turns off a D language feature identified by
id. The following values are supported:allTurns off all revertable D language features.
dip25Reverts https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md (Sealed references).
dtorfieldsTurns off generation for destructing fields of partially constructed objects.
markdownTurns off Markdown replacements in Ddoc comments.
- -fno-rtti#
Turns off generation of run-time type information for all user defined types. Any code that uses features of the language that require access to this information will result in an error.
- -fno-switch-errors#
This option controls what code is generated when no case is matched in a
final switchstatement. The default run time behavior is to throw aSwitchError. Turning off-fswitch-errorsmeans that instead the execution of the program is immediately halted.
- -funittest#
Turns on compilation of
unittestcode, and turns on theversion(unittest)identifier. This implies-fassert.
- -fversion=value#
Turns on compilation of conditional
versioncode into the program identified by any of the following values:levelSets the version level to
level, anyversioncode >=levelis compiled into the program.identTurns on compilation of
versioncode identified byident.
- -fno-weak-templates#
Turns off emission of declarations that can be defined in multiple objects as weak symbols. The default is to emit all public symbols as weak, unless the target lacks support for weak symbols. Disabling this option means that common symbols are instead put in COMDAT or become private.