Skip to content

[BUG] can not override a virtual function to pure virtual #1325

Open
@Xeverous

Description

@Xeverous

Describe the bug
cppfront does not allow to override a function into pure virtual. Whether base type function is pure or not has no impact.

To Reproduce
sample code:

base: type =
{
    d: (virtual move this);
    f: (virtual this) -> int = 1;
}

derived: type =
{
    this: base = ();
    f: (override this) -> int;
}

expected result - something like this:

class base
{
public:
    virtual ~base() = default;
    virtual int f() { return 1; } 
};

class derived : public base
{
public:
    int f() override = 0;
};

actual result: main.cpp2(10,5): error: a function must have a body ('=' initializer), unless it is virtual (has a 'virtual this' parameter) or is defaultable (operator== or operator<=>)

Command lines

cppfront main.cpp2 -p, built from commit dc3758a

Additional context

Conflicting documentation - https://hsutter.github.io/cppfront/cpp2/types/ says:

A pure virtual function is a function with a virtual this or override this parameter and no body.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions