decltype's operand doesn't consider friend declaration if it's used as a return type of the function. Following code failed. class X { int value ; friend class Y ; } ; class Y { public : template < typename T > static auto f(T t) -> decltype( t.value ) { return t.value ; // OK. Y is a friend of X. } } ; int main() { X x ; Y::f(x) ; // gcc issues error } The error message is In function 'int main()': error: 'int X::value' is private error: within this context It looks like access checking is done in the main rather than Y::f<X>.
confirmed if Y::f is not a template then access checking succeeds here's a C++03 version, which fails in the same way: class X { int value ; friend class Y ; } ; template <int> struct Int { }; class Y { public : template < typename T > static Int<sizeof(T::value)> f(T t) { return Int<sizeof(t.value)>(); } } ; int main() { X x ; Y::f(x) ; // gcc issues error }
Author: jason Date: Tue May 24 20:26:47 2011 New Revision: 174139 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174139 Log: PR c++/48884 * class.c (pushclass): Accept NULL argument. (popclass): Deal with popping null class. * pt.c (push_access_scope, pop_access_scope): Use them rather than push_to_top_level/pop_from_top_level. (push_deduction_access_scope, pop_defarg_context): New. (fn_type_unification): Use them. * name-lookup.c (lookup_name_real_1): Check current_class_type. Added: trunk/gcc/testsuite/g++.dg/template/access21.C trunk/gcc/testsuite/g++.dg/template/access22.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/class.c trunk/gcc/cp/name-lookup.c trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Author: jason Date: Wed May 25 01:08:46 2011 New Revision: 174163 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174163 Log: PR c++/48884 * pt.c (fn_type_unification): Disable access control during substitution. Added: branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/access21.C branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/access22.C Modified: branches/gcc-4_6-branch/gcc/cp/ChangeLog branches/gcc-4_6-branch/gcc/cp/pt.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Fixed for 4.6.1.