D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6610 - opAssign when copy-ing array
Summary: opAssign when copy-ing array
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P3 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-06 02:47 UTC by luka8088
Modified: 2024-12-13 17:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description luka8088 2011-09-06 02:47:02 UTC
/*
 * As discussed on #d @ freenode on 2011-09-06
 * Should this work ?
 *
 */

import std.stdio;

struct s {

  int a;
  int b;
  int c;

  void opAssign (s value) {

    // Should opAssign be call for each array member ?
    (&this)[0..1] = (&value)[0..1];

    // causes infinite loop (as it should)
    // this = value;

    this.c = 4;
  }
  
}

void main () {
  writeln("start");
  
  s s1;
  s1.a = 1;
  s1.b = 2;
  s1.c = 3;
  
  s s2;
  s2 = s1;
  
  writeln(s1.a, " ", s1.b, " ", s1.c); // 1 2 3
  writeln(s2.a, " ", s2.b, " ", s2.c); // 1 2 4

  writeln("end");
}
Comment 1 dlangBugzillaToGithub 2024-12-13 17:56:21 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18368

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB