<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I'm sure there are plenty of methods in Foundation that return a value which can be ignored. However, as Joe noticed, such functions are generally in minority.<div class=""><br class=""></div><div class="">I'd rather see a couple of `@allow_unused_result` than a dozen of `@warn_unused_result`.<br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><font color="#929292" class=""><br class="Apple-interchange-newline">Pozdrawiam – Regards,</font></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><font color="#929292" class="">Adrian Kashivskyy</font></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Wiadomość napisana przez Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt; w dniu 11.12.2015, o godz. 01:41:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 10, 2015 at 2:58 PM, Adrian Kashivskyy via swift-evolution<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class="">I think non-void functions should warn about their return value being unused<span class="Apple-converted-space">&nbsp;</span><b class="">by default</b>, thus eliminating the need to attribute&nbsp;them with @warn_unused_result.<br class=""><br class=""><b class="">Motivation</b><br class=""><br class="">It is a rare case for a result of a function to be unused – and most often it's caused by programmer having too little knowledge of the API. This, in my opinion, is a reasonable area of improvement for the compiler.<div class=""><br class=""></div><div class="">I also noticed that many of stdlib's functions are marked with this attribute, which supports my point of this being the default behavior.<br class=""><br class=""><b class="">Example code<br class=""></b><br class="">The following should be default behavior:<br class=""><br class=""><blockquote type="cite" class=""></blockquote><blockquote type="cite" class=""></blockquote><blockquote type="cite" class="">func square(x: Int) -&gt; Int { return x * x }<br class="">square(2) //&nbsp;warning: result of call to 'square' unused<br class=""></blockquote><br class="">Currently, unless annotated by @warn_unused_result, the compiler will not trigger any warnings.</div></div></blockquote><div class=""><br class=""></div><div class=""></div></div><div class="">We have discussed this internally in the past, and we found that non-mutating methods on structs and enums are usually @warn_unused_result, it is a quite strong heuristic.&nbsp; With classes, especially Cocoa ones, it might not be the case.&nbsp; It would be good if someone investigated how this change would affect a class-heavy library, e.g., Foundation.</div><div class=""><br class=""></div><div class="">Dmitri</div><div class=""><br class=""></div>--<span class="Apple-converted-space">&nbsp;</span><br class=""><div class="gmail_signature">main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank" class="">gribozavr@gmail.com</a>&gt;*/</div></div></div></div></blockquote></div><br class=""></div></body></html>