<div dir="ltr">My 2 cents: get rid of LLVM_UNUSED_RESULT, and move to LLVM_NODISCARD.<div><br></div><div>For compilers that support it, it should be a strict superset of features and functionality. The standard feature was written directly based on the clang warn_unused_result stuff.</div><div><br></div><div>I would just migrate us onto the spelling and usage pattern that got standardized. All we have to lose are warnings from compilers other than Clang until they implement this feature. That seems like not a huge loss to me honestly.</div><div><br></div><div>-Chandler</div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Sep 4, 2016 at 2:57 PM Sanjoy Das via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Justin,<br>
<br>
Justin Bogner wrote:<br>
 > Sanjoy Das<<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>>  writes:<br>
 >> Hi Justin,<br>
 >><br>
 >> This SGTM generally, but please make the difference between<br>
 >> LLVM_NODISCARD and LLVM_UNUSED_RESULT clear in the code. :)<br>
 ><br>
 > Right, this is where it gets a little weird. LLVM_NODISCARD would be for<br>
 > types, whereas LLVM_UNUSED_RESULT would be for functions. Depending on<br>
 > your host compiler, using the wrong one might DTRT, but it won't across<br>
 > all compilers.<br>
 ><br>
 > Do you think documenting this is sufficient, or should we try to name<br>
 > these to better represent where they should be used?<br>
<br>
Firstly, perhaps "LLVM_NODISCARD_TYPE" would be a better name?<br>
<br>
Secondly, if we define the following when the host compiler is clang,<br>
<br>
#define LLVM_UNUSED_RESULT __attribute__((warn_unused_result))<br>
#define LLVM_NODISCARD_TYPE [[clang::warn_unused_result]]<br>
<br>
via some shallow manual testing, it looks like using<br>
LLVM_NODISCARD_TYPE on a function should break the build (though I'd<br>
love it if someone more familiar with clang chimed in on this). So, is<br>
the problem that we can accidentally use LLVM_UNUSED_RESULT on a type<br>
and not know it?<br>
<br>
I think there is a dirty trick here -- we could:<br>
<br>
#define LLVM_UNUSED_RESULT __attribute__((warn_unused_result, enable_if(true, "")))<br>
#define LLVM_NODISCARD_TYPE [[clang::warn_unused_result]]<br>
<br>
This breaks the (clang) build if LLVM_UNUSED_RESULT is used on a type.<br>
<br>
It would still be possible to not do the right thing on GCC or MSVC<br>
and be able to build a binary, but I think as long as the clang bots<br>
catch bad uses we're okay.<br>
<br>
-- Sanjoy`<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>