<div dir="auto"><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_2918312180872913578WordSection1"><p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:Calibri,sans-serif;font-size:11pt">Regarding multi-entry functions, I'm aware of two cases where this occurs in a source language. One is when you have optional parameters in C++, which effectively
creates one or more overloads for the function; the other is PL/I which allows defining an entry label within the body of the function. For the C++ case, I'd expect the front-end to create stubs that fill in the defaulted parameters and then tail-call the
main function; in this case, each stub would have its own debug-info entry and be treated as its own independent function for debug-info purposes.</span></p></div></div></blockquote></div><div dir="auto">C++ doesn't work that way, parameters with default values are defined to evaluate the default values in the calling function then call with the results rather than creating a set of trampolines that evaluate the default values inside them.</div><div dir="auto"><br></div><div dir="auto">From <a href="https://en.cppreference.com/w/cpp/language/default_arguments">https://en.cppreference.com/w/cpp/language/default_arguments</a> :</div><div dir="auto">"The names used in the default arguments are looked up, checked for accessibility, and bound at the point of declaration, but are executed at the point of the function call"</div><div dir="auto"><br></div><div dir="auto">Note that a function with default arguments can't be cast to a function pointer that doesn't have those defaulted arguments. So, if there is a function:</div><div dir="auto">void f(int = 0);</div><div dir="auto">then the following cast won't compile:</div><div dir="auto">static_cast<void(*)()>(f);</div><div dir="auto"><br></div><div dir="auto">Note that the defined semantics for source_location::current() wouldn't work if default arguments worked as you described:</div><div dir="auto"><span style="font-family:sans-serif">source_location::current() is defined to return the location of the call-site when it is used in a default argument.</span></div><div dir="auto"><span style="font-family:sans-serif">In the following example, the assertion in f doesn't fail:</span></div><div dir="auto"><span style="font-family:sans-serif">void f(int line, source_location loc = </span><span style="font-family:sans-serif">source_location::current())</span></div><div dir="auto"><span style="font-family:sans-serif">{</span></div><div dir="auto"><span style="font-family:sans-serif"> assert(line == loc.line());</span></div><div dir="auto"><span style="font-family:sans-serif">}</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><div dir="auto" style="font-family:sans-serif">void g()</div><div dir="auto" style="font-family:sans-serif">{</div><div dir="auto" style="font-family:sans-serif"> f(__LINE__);</div><div dir="auto" style="font-family:sans-serif">}</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">void h()</div><div dir="auto" style="font-family:sans-serif">{</div><div dir="auto" style="font-family:sans-serif"> f(__LINE__);</div><div dir="auto" style="font-family:sans-serif">}</div><div dir="auto" style="font-family:sans-serif"><br></div>int main()</div><div dir="auto">{</div><div dir="auto"> g();</div><div dir="auto"> h();</div><div dir="auto">}</div><div dir="auto">See <a href="https://en.cppreference.com/w/cpp/experimental/source_location">https://en.cppreference.com/w/cpp/experimental/source_location</a></div><div dir="auto"><br></div><div dir="auto">Jacob Lifshay</div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div>