<div dir="ltr"><div dir="ltr">On Thu, Jun 29, 2023 at 12:01 PM Harald Achitz &lt;<a href="mailto:harald@swedencpp.se">harald@swedencpp.se</a>&gt; wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>&gt; Use a cast to (void) to suppress nodiscardness.</p>
    <p>Will not pass a code review, for reason<br></p></div></blockquote><div>I don&#39;t think you understand the status quo. I wasn&#39;t trying to express advice that &quot;Everyone should suppress nodiscardness at every turn.&quot;  I was simply expressing the actual fact that, <i><b>if</b></i> you want to suppress nodiscardness, <i><b>then</b></i> you should use (void). (Or a project-specific macro that expands to something like that.)</div><div>Obviously if your project has a coding guideline that states &quot;Thou shalt not suppress nodiscardness,&quot; then, corollary, thou shalt not use (void) casts, either.  (And this is great, because `(void)` is easily greppable.  Analogously, many projects state &quot;Thou shalt not use raw owning pointers,&quot; corollary, thou shalt not use `new T` either; and people grep for `new` and `delete` to verify that.)</div><div><br></div><div>For more on the messy state of [[nodiscard]]-suppression, see</div><div><a href="https://quuxplusone.github.io/blog/2019/01/25/nodiscard-philosophies/">https://quuxplusone.github.io/blog/2019/01/25/nodiscard-philosophies/</a><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><p>If auto _ silences nodiscard warnings,</p></div></blockquote><div>(It uses the result, so yes, it causes any warnings triggered by non-use not to be emitted. This isn&#39;t what I mean by &quot;suppression,&quot; though.)</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><p> I can guarantee you, it
      will land on the list of features not to use in some projects, and
      it will be a point of discussion if / when we move to new standard
      version.</p></div></blockquote><div>Okay.</div><div><br></div><div>You still seem to be operating under the misapprehension that a programmer might write either</div><div>    auto x = f();</div><div>or</div><div>    auto _ = f();</div><div>when what they actually meant to write was</div><div>    (void)f();</div><div>and then <i>you would let that mistake through code review</i>. My advice to you (both) is: Don&#39;t.</div><div>Furthermore, if you have a rule that &quot;Thou shalt never ignore the result of a [[nodiscard]] function,&quot; then you should actually be code-reviewing to make sure that results of [[nodiscard]] functions are always used. If, during code review, you see someone writing</div><div>    [[nodiscard]] int f();</div><div>    (void)f();  // X</div><div>    auto x = f(); (void)x;  // X</div><div>    [[maybe_unused]] auto x = f();  // X</div><div>    std::ignore = std::make_tuple(f());  // X<br></div><div>    []{}(f());  // X</div><div>etc. etc., you should flag the lines marked `X` in code review and tell them, &quot;Hey, we have a rule here that you&#39;re <i>never</i> supposed to suppress [[nodiscard]]ness! Go fix this code!&quot;</div><div>Complaining about the C++26 semantics of `_` doesn&#39;t seem productive to that end at all.</div><div><br></div><div>Arthur</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><blockquote type="cite"><div dir="ltr"><div class="gmail_quote">
        </div>
      </div>
    </blockquote>
  </div>

</blockquote></div></div>

