Skip to content

Constructor flow analysis doesn't understand noreturn #20811

@pbackus

Description

@pbackus

As of DMD 2.109.1, the following program fails to compile:

struct MustInit
{
    int n;
    @disable this();
    this(int n) { this.n = n; }
}

struct S
{
    MustInit member;
    this(bool b, int n, int m)
    {
        if (b == true) {
            member = MustInit(n);
            return;
        }
        if (b == false) {
            member = MustInit(m);
            return;
        }
        assert(0); // unreachable
    }
}

The error message is:

bug.d(11): Error: constructor bug.S.this field member must be initialized but skipped

Since the code path that skips the initialization of member contains assert(0), and will never return, this code should be allowed to compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions