<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 22, 2011, at 2:05 AM, Larisse Voufo wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Here's a basic example I've been trying to get to work:<br><br>explicit concept A<typename T> { <br> typename AType; <br><br> AType h(AType a) { <br> return a;<br> }<br><br> AType f(AType a) { <br>
AType b;<br>
return b;<br>
}<br>}<br><br>concept_map A<int> {<br> typedef char AType;<br>} <br><br>template<typename T><br>requires (A<T>) <br>void func(T a, AType b) {<br> AType x = h(b); // <-- Instantiation DOES NOT WORK<br>
AType y = f(b); // <-- Instantiation WORKS<br>}<br><br>int main(int argc, char **argv) <br>{ <br> func<int>(10, 'a'); // Fails with declaration for 'x', for passes with declaration of 'y'. <br>
}<br><br><br>It appears that during the instantiation of <b>func<int>()</b>, the value for input parameter '<b>b</b>' for '<b>func()</b>'<br>can be looked up no problem. However, that of '<b>a</b>' for associated function '<b>h()</b>' cannot. <br>
Instead, a call to <b>clang::LocalInstantiationScope::getInstantiationOf()</b> fails at runtime on the assertion:<br><br><b>(D->isInvalidDecl() && "declaration was not instantiated in this scope!")</b>.<br>
<br>I have been tracing through the procedures for building, transforming, and rebuilding Call Expressions -- as well as instantiating functions, noting each <br>execution of <b>clang::LocalInstantiationScope::getInstantiationOf()</b> and <b>clang::LocalInstantiationScope::InstantiatedLocal()</b>...<br>
<br>Still, I can't see what needs to be done differently for calls to <b>h()</b> from calls to <b>func<int>()</b>. Hence...<br><br>Question: <br>When/how exactly are input arguments bound to functions?<br></blockquote><div><br></div><div>That's a runtime issue. All the front-end does is enforce the calling convention on both sides of the call.</div><br><blockquote type="cite">Why would the current procedure fail to bind the value of '<b>b</b>' from the context of <b>func<int>()</b> to the <br>
parameter '<b>a</b>' of '<b>h()</b>' ?<br></blockquote></div><br><div>They are in completely different contexts. func<int>'s b is completely disjoint from h's a. And, in fact, they might not be the same thing, since passing 'b' as an argument to h() implies the creation of a temporary.</div><div><br></div><div>The only way I could see this issue coming up is if you're doing some kind of inlining of A<AType>::h into func<int> as part of instantiation. If so, I recommend against doing that: inlining will be handled by later optimization passes, and tangling the func<int> instantiation with the A<AType>::h instantiation is going to cause more problems in the front end than it solves.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Doug</div></body></html>