On Sunday, 30 June 2013 at 08:59:14 UTC, anonymous wrote:

void foo(const S s)
{
    data[0] = 42;
    assert(s.values[0] == 1);
}

With the postblit, the assert holds. Without it, it would fail. Isn't that problematic?

Ok, I see your point now. The function needs to be pure to elide postblit on a copy from a const variable to a const variable. The function doesn't need to be pure to elide postblit on a copy from immutable variable to const/immutable variable.

Although, if the compiler sees the function body, it could probably do some clever static analysis to see if it's possible that the const data is mutated, and elide the postblit if the answer is "no".

Reply via email to