[Issue 1730] New: const struct member func return invariant string can't assign to invariant string

Janice Caron caron800 at googlemail.com
Thu Dec 13 23:10:03 PST 2007


On 12/14/07, d-bugmail at puremagic.com <d-bugmail at puremagic.com> wrote:
> struct mystruct{
>         invariant(char)[] toChars()
>         {
>                 return "asdf";
>         }
> }
> void func(in mystruct s)
> {
>         invariant(char)[] k=s.toChars;
> }

That's correct behaviour, surely?

Change the function definition to

    const invariant(char)[] toChars()
    {
        return "asdf";
    }

and the problem should go away. toChars() as written is incorrectly
declared. It does not modify this, therefore it should be declared
const.

That said, I don't understant how s got to be const in the first
place! Does "in" make things const?


More information about the Digitalmars-d-bugs mailing list