[cfe-dev] Template default arg : Friend function cannot access private member
suyog sarda
sardask01 at gmail.com
Thu Sep 19 00:16:09 PDT 2013
This is regarding a test case which involves default argument
deduction/substitution. The test case can be summarized as :
template <class T, class = typename T::I>h(T){}
template <class T, class = typename T::I>j(T){}
class A
{
typedef int I;
friend void h<A>(A);
};
int main()
{
A a;
h(a);
j(a);
}
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
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
private member I.
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
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
function.
The standard says - (At 14.8.2 pt 8)
"If a substitution results in an invalid type or expression, type deduction
fails. An in valid type or expression
is one that would be ill-formed if written using the substituted arguments.
[ Note: Access checking is done as
part of the substitution process. —end note ]"
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
--
With regards,
Suyog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130919/5402398c/attachment.html>
More information about the cfe-dev
mailing list