<div dir="ltr">On Sun, Sep 22, 2013 at 3:01 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Chandler Carruth wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Sun, Sep 22, 2013 at 3:24 AM, Nick Lewycky <<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a><br></div><div class="im">
<mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>> wrote:<br>
<br>
The attached patch adds a new attribute named "enable_if" which<br>
takes an expression and a string. At the call site, the arguments<br>
are substituted into the enable_if expression (which is written in<br>
terms of the parameters) to determine whether this function is a<br>
viable candidate.<br>
<br>
<br>
What's the motivation? The C++ committee looked at just such a construct<br>
and currently is leaning in a different direction (concepts lite) so it<br>
seems odd to add this as an extension to Clang at this point.<br>
</div></blockquote>
<br>
C++ already has std::enable_if so I don't see any use for this in C++ code. (Technically it's a little stronger than std::enable_if because it doesn't perform any decay and template instantiation can, but I don't expect anybody to ever care.) It's for C code, and C headers included in C++ code.<br>
</blockquote><div><br></div><div>Actually, this is more powerful than what either std::enable_if or constraints (concepts lite) provide. This attribute allows overload resolution to depend on the *values* of function arguments (if they're constant expressions), not just their types. You can implement FORTIFY_SOURCE with this, for instance, and you can't implement it with constraints/std::enable_if.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The motivation is to provide a compiler extension that would allow C library authors to implement API checking rules, and more specifically the rules found in fortify. See the test/Sema/enable_if.c included in the patch for some examples.<div class="HOEnZb">
<div class="h5"><br>
<br>
Nick<br>
______________________________<u></u>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>