cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] Forwarding a function argument has different behaviour compared to C++ syntax 1

Open davide-pomi opened this issue 2 years ago • 0 comments
trafficstars

While in C++ syntax 1 constness is preserved when forwarding an argument to a function, in C++ syntax 2 the constness seems to be removed.

Syntax 1

void f(auto&& p) {
    p += 1;
}

void g() {
    {
        const auto p = 1;
        //f(p);  // this does not compile
    }
    {
        auto p = 1;
        f(p);
    }
}

Syntax 2

f : (forward p : int) = {
    p += 1;
}

g : () = {
    {
        const p = 1;
        f(p);  // this compiles
    }
    {
        p = 1;
        f(p);
    }
}

Shouldn't they both fail to compile?

davide-pomi avatar Nov 22 '22 21:11 davide-pomi