Thanks John for the reply. I got your point of "context to be checked where no special access is attached". Thanks a lot.<br><br><div class="gmail_quote">On Wed, Sep 25, 2013 at 1:28 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>></span> wrote:<br>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote"><div class="HOEnZb"><div class="h5">On Sep 19, 2013, at 12:16 AM, suyog sarda <<a href="mailto:sardask01@gmail.com">sardask01@gmail.com</a>> wrote:<br>
> This is regarding a test case which involves default argument deduction/substitution. The test case can be summarized as :<br>
><br>
><br>
> template <class T, class = typename T::I>h(T){}<br>
><br>
> template <class T, class = typename T::I>j(T){}<br>
><br>
> class A<br>
> {<br>
> typedef int I;<br>
> friend void h<A>(A);<br>
><br>
> };<br>
><br>
> int main()<br>
> {<br>
> A a;<br>
> h(a);<br>
> j(a);<br>
> }<br>
><br>
> gcc-4.8.1 throws error for function j, since it has been not been declared friend nor it is private to class A and hence violates access rule for<br>
><br>
> private member I(which is valid). gcc does not throw error for function h since it has been declared as friend to class A and hence can access<br>
><br>
> private member I.<br>
><br>
> Clang throws error for both the functions. Error for function j (not declared friend is valid and as expected), but it throws error even for<br>
><br>
> friend function h (error : deduction of default arg failed since I is a private member of class A). This violates the accessibility of the friend<br>
><br>
> function.<br>
><br>
> The standard says - (At 14.8.2 pt 8)<br>
><br>
><br>
> "If a substitution results in an invalid type or expression, type deduction fails. An in valid type or expression<br>
><br>
> is one that would be ill-formed if written using the substituted arguments. [ Note: Access checking is done as<br>
><br>
> part of the substitution process. —end note ]"<br>
><br>
><br>
> Can someone please provide inputs as to how to check where the access rights are being checked in clang? I am using QT creator to debug clang<br>
<br>
</div></div>Clang is actually rejecting the friend function declaration, not the call to h.<br>
<br>
The relevant bit from the standard is [class.access]p9:<br>
The names in a default template-argument have their access checked in the context in which they appear rather than at any points of use of the default template-argument.<br>
<br>
This is the resolution to DR 401:<br>
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2609.html#401" target="_blank">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2609.html#401</a><br>
<br>
Note in particular this quote, which illuminates the reasoning behind the somewhat confusing standard wording:<br>
We decided that template parameter default arguments should have their access checked in the context where they appear without special access for the entity declared…<br>
<br>
The context in which the template parameter default argument appears is the global context, which has no special access rights to A. So Clang is correct to reject this.<br>
<br>
GCC is probably mistakenly checking access from the context which uses the default argument. I can’t imagine that they’re really doing the heroics necessary to check access from the context of h<A> **in order to validate the declaration which makes that access well-formed**.<br>
<span class="HOEnZb"><font color="#888888"><br>
John.</font></span></blockquote></div><br><br clear="all"><br>-- <br>With regards,<br>Suyog Sarda<br>