<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">The sized deallocation functions in libc++ are currently marked as unavailable (with the availability attributes) before macosx10.12. This is fine since the required functions are not in the dylib prior to macosx10.12. However, we incorrectly trigger an error even when the sized deallocation functions are provided by the user. In other words, the following code triggers a compiler error because of the availability attributes:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">    $ cat <<EOF | clang++ -xc++ - -std=c++17 -mmacosx-version-min=10.11</font></div><div class=""><font face="Menlo" class="">    #include <new></font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">    void operator delete(void *p, std::size_t s) noexcept { }</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">    int main() {</font></div><div class=""><font face="Menlo" class="">      std::size_t size = 3;</font></div><div class=""><font face="Menlo" class="">      void* ptr = nullptr;</font></div><div class=""><font face="Menlo" class="">      ::operator delete(ptr, size);</font></div><div class=""><font face="Menlo" class="">    }</font></div><div class=""><font face="Menlo" class="">    EOF</font></div><div class=""><br class=""></div><div class="">Also note that even passing <font face="Menlo" class="">-fsized-deallocation</font> will not fix the problem, since it does not turn off the availability annotations. Here's how I think we should solve the problem (IIUC this is the same approach that was taken for aligned allocation):</div><div class=""><br class=""></div><div class="">1. In Clang: if the deployment target does not support sized deallocation, trigger an error whenever a sized deallocation function is used.</div><div class="">2. In Clang: take the deployment target into account when defining the feature-test macro <font face="Menlo" class="">__cpp_sized_deallocation</font>, i.e. do not define <font face="Menlo" class="">__cpp_sized_deallocation</font> when the deployment target is older than macosx10.12.</div><div class="">3. In Clang: when <font face="Menlo" class="">-fsized-deallocation</font> is passed on the command-line, define <font face="Menlo" class="">__cpp_sized_deallocation</font> regardless of other considerations, and do not trigger errors when sized allocation functions are used (regardless of the deployment target).</div><div class=""><br class=""></div><div class="">4. In libc++: remove the availability attributes on the sized deallocation functions.</div><div class="">5. In libc++: do not provide declarations for the sized deallocation functions when <font face="Menlo" class="">__cpp_sized_deallocation</font> is not defined (this is already the case today).</div><div class=""><br class=""></div><div class="">I have a couple of questions:</div><div class="">1. My understanding is that the bullets above describe what we did for aligned allocation -- is that correct?</div><div class="">2. Is there any reason not to do the above for sized deallocation? I think I remember Eric telling me they were different, but I’m not sure how.</div><div class="">3. Why do we even bother declaring the deallocation functions (and the allocation functions while we’re at it) in <font face="Menlo" class=""><new></font>, given they are implicitly declared by the compiler?</div><div class="">4. What makes sized deallocation and aligned allocation different from just any other function in the dylib is that users can define those functions themselves. Would it make sense to develop a more general mechanism for achieving the above? I'm sure we will see other similar functions in the future.</div><div class="">5. Why don’t we enable sized deallocation by default (when the proper requirements are met)? I think I remember hearing it was because sized deallocation is an ABI break, but I don’t remember the details.</div><div class=""><br class=""></div><div class="">I'm posting this to the list so that others can see the reasoning and chime in. I'm especially looking for feedback from Eric, who was involved in aligned allocation and (I think) knows all the details I’m looking for.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Louis</div><div class=""><br class=""></div></div></body></html>