<div dir="ltr"><br><div>Hi all,</div><div><br></div><div><div>clang version 3.4 (194264)</div><div>Target: i386-pc-linux-gnu</div><div>Thread model: posix</div></div><div><br></div><div>gcc version 4.8.1<br></div><div><br>
</div><div>This is with respect to the following test code:</div><div><br></div><div><div>struct A</div><div>{</div><div> ~A() = delete;</div><div>};</div><div><br></div><div><br></div><div>int main()</div><div>{</div><div>
A* ap = new A[5];</div><div>}</div></div><div><br></div><div>While g++ compiles it without any errors , clang throws an error:</div><div><br></div><div><div>test.cpp:9:11: error: attempt to use a deleted function</div><div>
A* ap = new A[5];</div><div> ^</div><div>test.cpp:3:3: note: function has been explicitly marked deleted here</div><div> ~A() = delete;</div><div> ^</div><div>1 error generated.</div></div><div><br></div><div>
My question is:</div><div><br></div><div>How does the destructor come into picture when we are not explicitly deleting the memory allocated? </div><div><br></div><div>The standard says: A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed.</div>
<div><br>But I suppose the destructor never gets called in this case. So ideally this test case should compile without any errors. Please correct me if my understanding is incorrect.</div><div><br></div><div><br></div><div>
Interestingly the error is not thrown when I tweak the test case to allocate a single instance instead of an array. Something like this:</div><div><br></div><div><div>struct A</div><div>{</div><div> ~A() = delete;</div><div>
};</div><div><br></div><div><br></div><div>int main()</div><div>{</div><div> A* ap = new A;</div><div>}</div></div><div><br></div><div>This piece of code compiles fine with both g++ and clang++ as expected.</div><div><br>
</div><div>Is this a potential bug in clang or am I missing something obvious??</div><div><br></div><div>Thanks,</div><div>Rahul</div><div><br></div><div><br></div></div>