Runtime Options (The GNU D Compiler)

### 1.2 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 `assert` contracts.

`-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-check` that allows more control as to where bounds checking is turned on or off. The following values are supported:

  ‘`on`’

    Turns on array bounds checking for all functions.

  ‘`safeonly`’

    Turns on array bounds checking only for `@safe` functions.

  ‘`off`’

    Turns 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 the `core.stdc` package is a built-in function.

`-fcheckaction=value` ¶

  This option controls what code is generated on an assertion, bounds check, or final switch failure. The following values are supported:

  ‘`context`’

    Throw an `AssertError` with extra context information.

  ‘`halt`’

    Halt the program execution.

  ‘`throw`’

    Throw an `AssertError` (the default).

`-fdebug` ¶
`-fdebug=value`

  Turn on compilation of conditional `debug` code into the program. The `-fdebug` option itself sets the debug level to `1`, while `-fdebug=` enables `debug` code that are identified by any of the following values:

  ‘`ident`’

    Turns on compilation of any `debug` code identified by ident.

`-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++03`’

    Sets `__traits(getTargetInfo, "cppStd")` to `199711`.

  ‘`c++11`’

    Sets `__traits(getTargetInfo, "cppStd")` to `201103`.

  ‘`c++14`’

    Sets `__traits(getTargetInfo, "cppStd")` to `201402`.

  ‘`c++17`’

    Sets `__traits(getTargetInfo, "cppStd")` to `201703`. This is the default.

  ‘`c++20`’

    Sets `__traits(getTargetInfo, "cppStd")` to `202002`.

  ‘`c++23`’

    Sets `__traits(getTargetInfo, "cppStd")` to `202302`.

`-finclude-imports` ¶

  Include imported modules in the compilation, as if they were given on the command line. When this option is enabled, all imported modules are compiled except those that are part of libphobos.

`-fno-invariants` ¶

  Turns off code generation for class `invariant` contracts.

`-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 when `main` is already defined in user code.

`-fno-moduleinfo` ¶

  Turns off generation of the `ModuleInfo` and 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 this` and `static ~this`), `unittest` code, and `DSO` registry 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 `out` contracts.

`-fno-preconditions` ¶

  Turns off code generation for precondition `in` contracts.

`-fpreview=id` ¶

  Turns on an upcoming D language change identified by id. The following values are supported:

  ‘`all`’

    Turns on all upcoming D language features.

  ‘`bitfields`’

    Implements bit-fields in D.

  ‘`dip1000`’

    Implements https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md (Scoped pointers).

  ‘`dip1008`’

    Implements https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1008.md (Allow exceptions in `@nogc` code).

  ‘`dip1021`’

    Implements https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md (Mutable function arguments).

  ‘`dip25`’

    Implements https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md (Sealed references).

  ‘`dtorfields`’

    Turns on generation for destructing fields of partially constructed objects.

  ‘`fieldwise`’

    Turns on generation of struct equality to use field-wise comparisons.

  ‘`fixaliasthis`’

    Implements new lookup rules that check the current scope for `alias this` before searching in upper scopes.

  ‘`fiximmutableconv`’

    Disallows unsound immutable conversions that were formerly incorrectly permitted.

  ‘`in`’

    Implements `in` parameters to mean `scope const [ref]` and accepts rvalues.

  ‘`inclusiveincontracts`’

    Implements `in` contracts of overridden methods to be a superset of parent contract.

  ‘`nosharedaccess`’

    Turns off and disallows all access to shared memory objects.

  ‘`rvaluerefparam`’

    Implements rvalue arguments to `ref` parameters.

  ‘`systemvariables`’

    Disables access to variables marked `@system` from `@safe` code.

`-frelease` ¶

  Turns on compiling in release mode, which means not emitting runtime checks for contracts and asserts. Array bounds checking is not done for `@system` and `@trusted` functions, 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:

  ‘`all`’

    Turns off all revertable D language features.

  ‘`dip1000`’

    Reverts https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md (Scoped pointers).

  ‘`dip25`’

    Reverts https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md (Sealed references).

  ‘`dtorfields`’

    Turns off generation for destructing fields of partially constructed objects.

  ‘`intpromote`’

    Turns off C-style integral promotion for unary `+`, `-` and `~` expressions.

`-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 switch` statement. The default run time behavior is to throw a `SwitchError`. Turning off `-fswitch-errors` means that instead the execution of the program is immediately halted.

`-funittest` ¶

  Turns on compilation of `unittest` code, and turns on the `version(unittest)` identifier. This implies `-fassert`.

`-fversion=value` ¶

  Turns on compilation of conditional `version` code into the program identified by any of the following values:

  ‘`ident`’

    Turns on compilation of `version` code identified by ident.

`-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.