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.


Encapsulates file/line/column locations.

Source location.d

enum MessageStyle: ubyte;
How code locations are formatted for diagnostic reporting
filename.d(line): message
struct Loc;
A source code location
Used for error messages, __FILE__ and __LINE__ tokens, __traits(getLocation, XXX), debug info etc.
static immutable Loc initial;
use for default initialization of const ref Loc's
static nothrow void set(bool showColumns, MessageStyle messageStyle);
Configure how display is done
bool showColumns when to display columns
MessageStyle messageStyle digitalmars or gnu style messages
const nothrow @nogc @safe uint charnum();

nothrow @nogc @safe uint charnum(uint num);
utf8 code unit index relative to start of line, starting from 1
const nothrow @nogc @safe uint linnum();

nothrow @nogc @safe uint linnum(uint num);
line number, starting from 1
const nothrow @nogc const(char)* filename();
filename for this location, null if none
nothrow @trusted void filename(const(char)* name);
Set file name for this location
const(char)* name file name for location, null for no file name
const nothrow bool equals(ref const(Loc) loc);
Checks for equivalence by comparing the filename contents (not the pointer) and character location.


  • Uses case-insensitive comparison on Windows
  • Ignores charnum if Columns is false.

const nothrow @nogc @trusted bool opEquals(ref const(Loc) loc);

const nothrow @trusted size_t toHash();
opEquals() / toHash() for AA key usage
Compare filename contents (case-sensitively on Windows too), not the pointer - a static foreach loop repeatedly mixing in a mixin may lead to multiple equivalent filenames (foo.d-mixin-<line>), e.g., for test/runnable/test18880.d.
const pure nothrow @safe bool isValid();
true if Loc has been set to other than the default initialization