Opened 5 years ago
#238 new defect
Function new incorrectly creates temporary objects
| Reported by: | Thierry Delisle | Owned by: | |
|---|---|---|---|
| Priority: | critical | Component: | cfa-cc |
| Version: | 1.0 | Keywords: | new |
| Cc: |
Description
This code leads to a call to a copy constructor that is incorrect.
#include <stdlib.hfa>
#include <fstream.hfa>
struct cluster {};
void ?{}(cluster & this) { sout | "Cluster Ctor"; }
void ?{}(cluster & this, cluster ) { sout | "Cluster CopyCtor"; }
struct inner {
cluster * cl;
};
void ?{}(inner & this, cluster & ) { sout | "Inner Ctor"; }
struct outer {
inner * in;
};
void ?{}(outer & this, cluster & cl ) {
this.in = new(cl);
}
void ^?{}(outer & this) { delete(this.in); }
int main() {
cluster cl;
outer o = { cl };
}
The output is:
Cluster Ctor Cluster CopyCtor Inner Ctor
but the CopyCtor should not be called.
Note:
See TracTickets
for help on using tickets.