GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Learn
  • Documentation
  • Language Reference
  • Library Reference
  • Command-line Reference
  • Feature Overview
  • Articles
  • Downloads
  • Packages
  • Community
  • Blog
  • Orgs using D
  • Twitter
  • Discord (community-run)

This view

  • Original page
  • New address

GeezerVison is showing dlang.org — Legacy Code - D Programming Language

D Logo
Menu
  • Learn
  • Documentation
    • Language Reference
    • Library Reference
    • Command-line Reference
    • Feature Overview
    • Articles
  • Downloads
  • Packages
  • Community
    • Blog
    • Orgs using D
    • Twitter
    • Discord (community-run)
    • Forums
    • IRC
    • Wiki
    • Issues
    • Contributing
    • Contributors
    • Foundation
    • Security Team
    • Store
    • Donate
    • Sponsors
  • Resources
    • Tour
    • Books
    • Tutorials
    • Tools
    • Editors
    • IDEs
    • run.dlang.io
    • Visual D
    • Acknowledgments
    • D Style
    • Glossary
    • Sitemap
Search

Language Reference

table of contents

  • Introduction
  • Lexical
  • Interpolation Expression Sequence
  • Grammar
  • Modules
  • Declarations
  • Types
  • Properties
  • Attributes
  • Pragmas
  • Expressions
  • Statements
  • Arrays
  • Associative Arrays
  • Structs and Unions
  • Classes
  • Interfaces
  • Enums
  • Type Qualifiers
  • Functions
  • Operator Overloading
  • Templates
  • Template Mixins
  • Contract Programming
  • Conditional Compilation
  • Traits
  • Error Handling
  • Unit Tests
  • Garbage Collection
  • Floating Point
  • D x86 Inline Assembler
  • Embedded Documentation
  • Interfacing to C
  • Interfacing to C++
  • Interfacing to Objective-C
  • Portability Guide
  • Named Character Entities
  • Memory Safety
  • Application Binary Interface
  • Vector Extensions
  • Better C
  • ImportC
  • Live Functions
  • Windows Programming
  • Glossary
  • Legacy Code
  • Editions
Report a bug
If you spot a problem with this page, click here to create a GitHub 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.

Legacy Code

Contents
  1. body keyword
  2. alias target name; syntax
  3. Aliasing an instance member

To maintain compatibility with older D code, many legacy features remain supported. This page describes each legacy feature that is supported, with a suggestion of how to modernize the code.

Legacy Features
FeatureSummaryEdition check
body keywordbody after a contract statement - use do instead2024
alias target name; syntaxuse alias name = target; instead2024
Aliasing an instance member Use typeof(instance).member instead2024
Escaping scope data scope is enforced in @safe code2024
Struct/union postblituse a copy constructor instead.

body keyword

body was a keyword used to specify a function/method's body after a contract statement:

class Foo
{
    void bar(int i)
    in { assert(i >= 42); }
    body { /* Do something interesting */ }

    string method(string s)
    out(v) { assert(v.length == s.length); }
    body { /* Do something even more interesting */ }

    void noBody() { /* No contracts, no body */ }
}

Corrective Action

Use the do keyword instead (introduced in v2.075.0):

void bar(int i)
in { assert(i >= 42); }
do { /* Look ma, no body! */ }
Rationale: The body keyword was only used for this single purpose. Since D grammar aims to be context free, this common word was reserved, which led to frequent trouble for people interfacing with other languages (e.g. javascript) or auto-generating code.

alias target name; syntax

From the 2024 edition, AliasDeclaration only supports alias name = target; syntax. This is easier to find the symbol identifier, particularly when target is a complex symbol. The target first order came from C's typedef syntax.

Aliasing an instance member

E.g. alias a = instance.field;. Such an alias actually aliases a member of the instance's type, not the instance member itself. That could be confusing. Instead, alias a member of the type.

Note: Aliasing this.member and super.member are valid inside methods.
struct Bar
{
    Foo f;
    alias v = f.v; // Error, use `typeof(f).v`
}

struct Foo
{
    int v;
    void test(Foo that) const
    {
        alias a = this.v; // OK
        alias b = that.v; // Error, use `typeof(that).v` instead
        assert(&a is &b); // passes
        assert(&b !is &that.v);
    }
}
Glossary
Editions
Copyright © 1999-2026 by the D Language Foundation | Page generated by Ddoc on Mon Nov 9 05:59:20 2026
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.