<div dir="ltr">I think this is the intended use of enable_if, no?<div><br></div><div><a href="http://en.cppreference.com/w/cpp/types/enable_if">http://en.cppreference.com/w/cpp/types/enable_if</a><br></div><div>"This metafunction is a convenient way to leverage SFINAE to conditionally remove functions from overload resolution based on type traits and to provide separate function overloads and specializations for different type traits"</div><div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 10, 2016 at 11:07 PM, Luo, Xionghu via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="ZH-CN" link="#0563C1" vlink="#954F72">
<div>
<p class="MsoNormal"><span lang="EN-US">Hi Chandler,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I scanned the LLVM source code, and found some potential code issues, take the piece of code in file ‘./include/llvm/Support/Allocator.h’ for example:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%">
<tbody>
<tr>
<td width="50" valign="top" style="width:30.0pt;border:none;border-right:solid lightgrey 1.0pt;padding:0cm 3.75pt 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#555555">80<u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm"></td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="margin-left:6.0pt;text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"> 
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">///</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">\brief</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">Deallocate</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">space</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">for</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">a</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">sequence</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">of</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">objects</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">without</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">constructing</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:gray">them.</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"><u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" valign="top" style="width:30.0pt;border:none;border-right:solid lightgrey 1.0pt;padding:0cm 3.75pt 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#555555">81<u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm"></td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="margin-left:6.0pt;text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"> 
</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">template</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"> <</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">typename</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
 T><u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" valign="top" style="width:30.0pt;border:none;border-right:solid lightgrey 1.0pt;padding:0cm 3.75pt 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#555555">82<u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm"></td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="margin-left:6.0pt;text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"> 
</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">typename</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">std</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">::enable_if<<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" valign="top" style="width:30.0pt;border:none;border-right:solid lightgrey 1.0pt;padding:0cm 3.75pt 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#555555">83<u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm"></td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="margin-left:6.0pt;text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">      !</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">std</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">::is_same<</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">typename</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">std</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">::remove_cv<T>::</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">type</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">,
</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">void</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">>::</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">value</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">,
</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">void</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">>::</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">type</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"><u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" valign="top" style="width:30.0pt;border:none;border-right:solid lightgrey 1.0pt;padding:0cm 3.75pt 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#555555">84<u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#111111"><img width="11" height="15" src="cid:image005.png@01D1AB8E.674ADC00" alt="https://otckw.jf.intel.com:8080/review/review/images/folding/collapse_top.png"></span><span lang="EN-US" style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#111111"><u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="margin-left:6.0pt;text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">  Deallocate(T *Ptr,
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">size_t</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"> Num =
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">1</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">) {<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" valign="top" style="width:30.0pt;border:none;border-right:solid lightgrey 1.0pt;padding:0cm 3.75pt 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#555555">85<u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm"></td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="margin-left:6.0pt;text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">   
</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:blue">Deallocate</span><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">(</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">static_cast</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"><</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">const</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">
</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">void</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111"> *>(Ptr), Num *
</span><b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:navy">sizeof</span></b><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">(T));<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" valign="top" style="width:30.0pt;border:none;border-right:solid lightgrey 1.0pt;padding:0cm 3.75pt 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#555555">86<u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#111111"><img width="11" height="15" src="cid:image006.png@01D1AB8E.674ADC00" alt="https://otckw.jf.intel.com:8080/review/review/images/folding/collapse_bottom.png"></span><span lang="EN-US" style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#111111"><u></u><u></u></span></p>
</td>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="left" style="margin-left:6.0pt;text-align:left"><span lang="EN-US" style="font-size:9.0pt;font-family:"Courier New";color:#111111">  }<u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">If the typename T is void, the std::is_same will be FALSE, which means the std::enable_if::type is UNDEFIED.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">So do you think it need a fix?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks.<u></u><u></u></span></p>
<p class="MsoNormal"><span><span lang="EN-US" style="font-size:8.5pt;font-family:"Helvetica",sans-serif;color:#111111"><u></u> <u></u></span></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#44546a">Luo
</span><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#1f497d">Xionghu</span><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#44546a"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#44546a">Best Regards<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
</div>
</div>

<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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>
<br></blockquote></div><br></div>