On Wednesday, 20 August 2014 at 20:46:20 UTC, Paul D Anderson wrote:
Re-compiling existing code with version 2.066 generates a lot of errors complaining about implicit conversion to const. Typical is this call (inside a struct with properties 1 & 2):

        z.sign = x.sign ^ y.sign;

Error: None of the overloads of 'sign' are callable using argument types bool (const), candidates are:

1)      @property
        @safe
        bool sign() const
        {
                return signed;
        }

2)      @property
        @safe
        bool sign(in bool value)
        {
                signed = value;
                return signed;
        }

What changed? It ran okay with early beta versions, but not with the release.

Paul

The problem (not obvious from the above) is that a templated type is bringing its qualifiers into the template.

Here is a small example:

T add(T)(in T x, in T y)
{
        T z;
        z = x + y;
        return z;
}

void main()
{
        const double a = 1.0;
        const double b = 2.0;
        double c;
        c = add(a,b);
}

Error: Cannot modify immutable expression z

---

Since a and b are const double the deduced template type is also const double. Then when z is declared as type T it is also const.

This compiled and ran in beta 5 but not in beta 6.

If I modify the above so that declaration and assignment are performed at the same time:

        T z = x + y;

This compiles and assigns the (const double) value 3.0 to z. After the function call c contains the double value 3.0, but it is no longer const.

The error can be avoided by declaring z to be of type Unqual!T in most cases.

I don't know if this is expected behavior that just wasn't enforced before, or if this is something new. Either way I don't like it. And I'm a little surprised I'm the only one affected by this. I'll keep digging.

Paul

Reply via email to