Topic: [C++0x] Member accessibility and decltype problem
Author: Jamboree<tongari95@gmail.com>
Date: Wed, 24 Aug 2011 14:52:05 -0700 (PDT) Raw View
Greetings,
I have a problem using decltype with some expression which involves
the private function call of some class.
I'm not sure it's a g++ bug or it's standard conformed, I'm using g+
+4.5.2/MinGW.
The following is a *contrived* example that illustrates the problem, I
hope you can get the idea:
--------------------------------------------------------------------------
// A non-member non-friend utility that needs to deduce the result
type of T::call(p).
template<class T, class P>
auto indirect_call(P p) -> decltype(T::call(p))
{
return T::call(p);
}
class A
{
//
// These ought to be used internally.
//
void private_fn() {}
typedef void private_fn_result_type;
struct UseDecltype
{
template<class P>
static
auto call(P p) -> decltype(p->private_fn())
{
return p->private_fn();
}
};
struct UseTypedef
{
template<class P>
static
A::private_fn_result_type call(P p)
{
return p->private_fn();
}
};
public:
void use_decltype() // This NOT compiles
{
indirect_call<UseDecltype>(this);
}
void use_typedef() // This compiles
{
indirect_call<UseTypedef>(this);
}
};
--------------------------------------------------------------------------
UseDecltype& UseTypedef are both private of A, but UseXXX::call is
public-callable so we can use indirect_call<T>, but note that
indirect_call is an external utility which is neither member nor
friend.
In the case of UseTypedef, it works fine even
A::private_fn_result_type is private;
In the case of UseDecltype, it fails to compile because the compiler
complains that private_fn() which used in decltype is private of A...
The problem here:
Even though UseDecltype::call is public to indirect_call, but its
deduced type isn't, hmmm....
Could anybody shed some light on this matter?
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]