<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br></div><div><br>On Sep 13, 2017, at 8:11 AM, JF Bastien <<a href="mailto:jfbastien@apple.com">jfbastien@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html; charset=utf-8">Hello WebCritters,<div class=""><br class=""></div><div class="">I’m moving some code around, and one particular header I have is included everywhere in JSC so I’d like it to be lightweight and include as few other headers as possible. It unfortunately uses <font face="Courier New" class="">WTF::Vector</font>, but it only does so as a pointer:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Courier New" class="">void ohNoes(Vector<Noms>*);</font></div></blockquote><div class=""><br class=""></div><div class="">It seems like something a forward declaration would fix nicely, and oh joy and wonder we have <font face="Courier New" class="">Forward.h</font> just for this! Here’s what it does:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Courier New" class="">template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> class Vector;</font></div></div></blockquote><div class=""><br class=""></div><div class="">That’s nice and great for <font face="Courier New" class="">T</font>, but all the other template parameters are SOL because <font face="Courier New" class="">Vector</font> is actually declared with default template parameters:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Courier New" class="">template<typename T, size_t inlineCapacity = 0, typename OverflowHandler = CrashOnOverflow, size_t minCapacity = 16, typename Malloc = FastMalloc></font></div></div><div class=""><div class=""><font face="Courier New" class="">class Vector : private VectorBuffer<T, inlineCapacity, Malloc> {</font></div></div></blockquote><div class=""><br class=""></div><div class="">The extra painful thing is that, contrary to what I originally thought, one <i class="">cannot</i> declare <span style="font-family: "Courier New";" class="">Vector</span> in <font face="Courier New" class="">Forward.h</font> and then define it in <span style="font-family: "Courier New";" class="">Vector.h</span> with the same defaults twice! Ideally the compiler would just yell at a mismatch, but instead it says <font face="Courier New" class="">error: template parameter redefines default argument</font> (thanks clang, that’s exactly what I’m trying to do, just tell me if you catch a mismatch and ODR away otherwise).</div><div class=""><br class=""></div><div class="">Here’s what I propose:</div><div class=""><br class=""></div><div class=""><ol class="MailOutline"><li class="">Change the forward declaration in <font face="Courier New" class="">Forward.h</font> to contain the default template parameters (and forward-declare <font face="Courier New" class="">CrashOnOverflow</font>).</li><li class="">Remove these default template parameters from <span style="font-family: "Courier New";" class="">Vector.h</span>.</li></ol></div></div></blockquote>When looking for default parameters, I would expect to find them next to the Vector definition. If we do this, #4 should be required.<br><blockquote type="cite"><div><div class=""><ol class="MailOutline" start="3"><li class="">Include <font face="Courier New" class="">Forward.h</font> in <span style="font-family: "Courier New";" class="">Vector.h</span>.</li><li class="">Optionally, if the WebCritters think it useful, leave a comment just above the <span style="font-family: "Courier New";" class="">Vector</span> definition redirecting to <font face="Courier New" class="">Forward.h</font> for defaults (or more fancy, use <font face="Courier New" class="">size_t inlineCapacity /*=0*/</font> style like LLVM’s codebase does, and have a tool that checks for consistency).</li><li class="">Optionally, try to fix C++20 so this isn’t A Thing anymore. Note that my hopes are low because of modules (why fix it if modules will magically make this not a thing).</li></ol></div><div class=""><br class=""></div><div class="">Alternatively, I could just include <span style="font-family: "Courier New";" class="">Vector.h</span> and be done with it.</div><div class=""><br class=""></div><div class="">Thoughts?</div><div class=""><br class=""></div><div class="">JF</div><div class=""><br class=""></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>webkit-dev mailing list</span><br><span><a href="mailto:webkit-dev@lists.webkit.org">webkit-dev@lists.webkit.org</a></span><br><span><a href="https://lists.webkit.org/mailman/listinfo/webkit-dev">https://lists.webkit.org/mailman/listinfo/webkit-dev</a></span><br></div></blockquote></body></html>