compare struct with string member is wield;

Jonathan M Davis jmdavisProg at gmx.com
Tue Oct 11 23:14:46 PDT 2011


On Wednesday, October 12, 2011 06:07:38 Cheng Wei wrote:
> Sorry. The previous is not the one causes the problem.
> Try this:
> 
> struct S {
>     string str = "Hello";   // Adding an initial value here.
> };
> 
> S g_s;
> 
> unittest {
>     S s1;
>     S s2;
>     assert(s1 == s2); // Success
>     assert(g_s == s1); // Fail
>     auto s3 = g_s;
>     assert(s3 == g_s);; // Even this will fail.
> }
> 
> It seems if the string is initialized with a default value, then this
> does not work.

Yeah. It's failing for me too. It's obviously a bug of some kind. I'd have to 
going digging through d.puremagic.com/issues to see whether anything like it 
has been reported though.

By the way, the semicolon at the end of the definition of S is unnecessary in 
D.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list