<p dir="ltr">René, </p>
<p dir="ltr">But your code is not property written actually. </p>
<p dir="ltr">Foo *bar = new Foo() ; *won't* return null on failure, it will throw an std::bad_alloc, so your code is actually not doing anything, just a pointless if, that will always succeed. </p>
<p dir="ltr">If you really, really wanna check for new failures, you must use a try / catch idiom or use new + nothrow. </p>
<p dir="ltr">But it's pointless. If there's not enough memory to create a object the program shouldn't continue because it has not enough memory to work with. <br>
</p>
<div class="gmail_quote">Em 26 de mai de 2016 07:23, "René J.V. Bertin" <<a href="mailto:rjvbertin@gmail.com">rjvbertin@gmail.com</a>> escreveu:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div style="font-family:Verdana,Arial,Helvetica,Sans-Serif">
<table bgcolor="#f9f3c9" width="100%" cellpadding="12" style="border:1px #c9c399 solid;border-radius:6px">
<tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="https://git.reviewboard.kde.org/r/128016/" target="_blank">https://git.reviewboard.kde.org/r/128016/</a>
</td>
</tr>
</table>
<br>
<blockquote style="margin-left:1em;border-left:2px solid #d0d0d0;padding-left:10px">
<p style="margin-top:0">On May 26th, 2016, 10:56 a.m. CEST, <b>Sven Brauch</b> wrote:</p>
<blockquote style="margin-left:1em;border-left:2px solid #d0d0d0;padding-left:10px">
<table width="100%" border="0" bgcolor="white">
<thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom:1px solid #c0c0c0;font-size:9pt;padding:4px 8px;text-align:left">
<a href="https://git.reviewboard.kde.org/r/128016/diff/1/?file=465464#file465464line99" style="color:black;font-weight:bold;text-decoration:underline" target="_blank">sublime/idealdockwidget.cpp</a>
<span style="font-weight:normal">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<th bgcolor="#e9eaa8" style="border-right:1px solid #c0c0c0" align="right"><font size="2">99</font></th>
<td bgcolor="#fdfebc" width="50%"><pre style="font-size:8pt;line-height:140%;margin:0"> <span>menu</span><span>.</span><span>addSection</span><span>(</span><span>windowIcon</span><span>(),</span> <span>m_view</span><span>-></span><span>document</span><span>()</span><span>-></span><span>title</span><span>());</span></pre></td>
<th bgcolor="#e9eaa8" style="border-left:1px solid #c0c0c0;border-right:1px solid #c0c0c0" align="right"><font size="2">99</font></th>
<td bgcolor="#fdfebc" width="50%"><pre style="font-size:8pt;line-height:140%;margin:0"> <span>if</span> <span>(</span><span>!</span><span>menu</span><span>)</span> <span>{</span></pre></td>
</tr>
</tbody>
</table>
<pre style="white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word"><p style="padding:0;margin:0;line-height:inherit;white-space:inherit">Don't do this. It just clutters the code, and you would have to fix it in about every second line of the application anyways, should it ever happen (it doesn't on linux).</p></pre>
</blockquote>
<p>On May 26th, 2016, 11:08 a.m. CEST, <b>René J.V. Bertin</b> wrote:</p>
<blockquote style="margin-left:1em;border-left:2px solid #d0d0d0;padding-left:10px">
<pre style="white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word"><p style="padding:0;margin:0;line-height:inherit;white-space:inherit">I don't understand what you're implying here. Not doing this would either mean not using a pointer at all (= abandoning the patch), or not checking if the allocation succeeded. And that's not acceptable either. No matter how likely an application is to crash anyway if an allocation fails.
>From what I see this is true also when using a QScopedPointer.</p></pre>
</blockquote>
<p>On May 26th, 2016, 11:46 a.m. CEST, <b>Sven Brauch</b> wrote:</p>
<blockquote style="margin-left:1em;border-left:2px solid #d0d0d0;padding-left:10px">
<pre style="white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word"><p style="padding:0;margin:0;line-height:inherit;white-space:inherit">Nowhere in KDE code does anybody ever check if an allocation succeeds. IMO it's pedantic and useless. We are not writing life-critical software; if your system is out of memory, your IDE crashes, such is life. On Linux it doesn't do anything <em style="padding:0;margin:0;line-height:inherit;white-space:normal">anyways</em> in the default kernel configuration, since allocations always succeed.</p></pre>
</blockquote>
</blockquote>
<pre style="margin-left:1em;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word"><p style="padding:0;margin:0;line-height:inherit;white-space:inherit">I just don't agree with that. If you really insist on not checking here, I'd propose that you remove the 2 lines in a separate commit, because I don't want to go on permanent record not doing things properly.</p>
<p style="padding:0;margin:0;line-height:inherit;white-space:inherit">Writing proper code is indeed pedantic. Is it useless? What's the percentage of security fixes that we would NOT see if everyone always checked against NULL before using a pointer? </p>
<blockquote style="padding:0 0 0 1em;border-left:1px solid #bbb;white-space:normal;margin:0 0 0 0.5em;line-height:inherit">
<p style="padding:0;margin:0;line-height:inherit;white-space:inherit">allocations always succeed.</p>
</blockquote>
<p style="padding:0;margin:0;line-height:inherit;white-space:inherit">I'm not sure if I should be in awe for a kernel that apparently is able to provide more memory than I could ever afford to buy, or lose quite a bit of esteem for inciting lazy and sloppy programming practices...</p></pre>
<br>
<p>- René J.V.</p>
<br>
<p>On May 25th, 2016, 10:54 p.m. CEST, René J.V. Bertin wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="12" style="border:1px #888a85 solid;border-radius:6px">
<tr>
<td>
<div>Review request for KDevelop.</div>
<div>By René J.V. Bertin.</div>
<p style="color:grey"><i>Updated May 25, 2016, 10:54 p.m.</i></p>
<div style="margin-top:1.5em">
<b style="color:#575012;font-size:10pt">Repository: </b>
kdevplatform
</div>
<h1 style="color:#575012;font-size:10pt;margin-top:1.5em">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border:1px solid #b8b5a0">
<tr>
<td>
<pre style="margin:0;padding:0;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word"><p style="padding:0;margin:0;line-height:inherit;white-space:inherit">OS X can be capricious when instances corresponding to a widget are deleted, if the class in question uses "native" ObjC SDKs behind the scenes. Pending events can in that case be (generated and) delivered to objects that were already deleted.
According to the documentation, one should prefer to use <code style="color:#4444cc;padding:0;white-space:normal;margin:0;line-height:inherit">QObject::deleteLater()</code> rather than the regular, direct <code style="color:#4444cc;padding:0;white-space:normal;margin:0;line-height:inherit">delete</code> whether it be explicit or implicit.</p>
<p style="padding:0;margin:0;line-height:inherit;white-space:inherit">I've long used a local patch that uses this approach in order to prevent a recurring crash after using the context menu of the "ideal dock widget". Somehow I never put it up for review here, apparently.</p></pre>
</td>
</tr>
</table>
<h1 style="color:#575012;font-size:10pt;margin-top:1.5em">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border:1px solid #b8b5a0">
<tr>
<td>
<pre style="margin:0;padding:0;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word"><p style="padding:0;margin:0;line-height:inherit;white-space:inherit">Builds and permits reliable behaviour on both OS X and Linux.</p></pre>
</td>
</tr>
</table>
<h1 style="color:#575012;font-size:10pt;margin-top:1.5em">Diffs </h1>
<ul style="margin-left:3em;padding-left:0">
<li>sublime/idealdockwidget.cpp <span style="color:grey">(dae0ea2)</span></li>
</ul>
<p><a href="https://git.reviewboard.kde.org/r/128016/diff/" style="margin-left:3em" target="_blank">View Diff</a></p>
</td>
</tr>
</table>
</div>
</div>
<br>_______________________________________________<br>
KDevelop-devel mailing list<br>
<a href="mailto:KDevelop-devel@kde.org">KDevelop-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kdevelop-devel" rel="noreferrer" target="_blank">https://mail.kde.org/mailman/listinfo/kdevelop-devel</a><br>
<br></blockquote></div>