Bug 10929 – [CTFE] Destructor errornously gets called on NRVO-ed structs?
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-30T11:33:00Z
Last change time
2014-02-13T17:27:19Z
Keywords
CTFE, pull, wrong-code
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2013-08-30T11:33:52Z
If CTFE did full copy with postblit and dtor-ed temporary it would be more or less OK.. but instead it seemingly moves struct but calls dtor.
(this bug blocks development of std.regex, marking as critical)
Test case shows difference between R-T and C-T:
struct Destroyable{
this(this)
{
postblitCount++;
}
~this(){
payload = 0;
dtorCount++;
}
int payload;
int dtorCount;
int postblitCount;
}
auto make()
{
auto val = Destroyable(42, 0);
return val;
}
enum dg = (){
auto val = make();
assert(val.postblitCount == 0); //passes in both modes
assert(val.dtorCount == 1); //passes at CT -- WAT?
//at R-T the above assertion fails as expected
return 0;
};
enum test_me = dg();
int main(){
return dg();
};