Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 16108: to!string fails on struct with disabled postblit #5425

Merged
merged 1 commit into from
Jun 11, 2017

Conversation

JackStouffer
Copy link
Member

Enables conversions to string for structs with a disabled postblit

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
16108 to!string fails on struct with disabled postblit

if (isAggregateType!S && !isCopyable!S)
{
return toImpl!T(arg);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these not be merged into a single

T to(A...)(auto ref A args)

i.e. amending the very first overload and removing the "fix issue" overloads?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because then you would be modifying the behavior of the function for several types, most notably ranges.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow. Right now we have overloads in to and overloads in toImpl, with "fix issue" to overloads having the same constraints as their toImpl counterparts. Can we not have just the toImpl overloads? What am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry I didn't see your proposed template signature and misunderstood.

Well, you definitely never want to pass a static array by value, as that would cause a lot of the code to return references to stack data. That's why the original special case was added.

Copy link
Contributor

@radcapricorn radcapricorn May 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now, this prevents matching against other toImpl overloads. Thanks.

std/conv.d Outdated
auto a = A();
assert(to!string(a) == "0:false");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a test without a custom toString?

@safe pure unittest
{
    static struct B
    {
        int val;
        bool flag;

        @disable this(this);
    }

    auto b = B();
    assert(b.to!string == "B(0, false)");
}

@JackStouffer
Copy link
Member Author

@wilzbach Added

Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dlang-bot dlang-bot merged commit 4f2d89b into dlang:master Jun 11, 2017
@JackStouffer JackStouffer deleted the issue16108 branch June 11, 2017 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants