Does std::reference_wrapper<T>
allow T
to be incomplete, in the same way that a T&
can be dealt with without T
being complete?
GCC 4.9 accepts the following:
#include <functional>
struct woof;
struct test
{
test(woof& w) : w(w) {}
std::reference_wrapper<woof> w;
};
struct woof
{
int a;
};
int main()
{
woof w;
test t = w; // (braced-init would be better, but VS2012!)
}
But MSVS 2012 rejects it with the following message:
Error 1 error C2139: 'woof' : an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_abstract' c:\program files (x86)\microsoft visual studio 11.0\vc\include\type_traits 755 1 test3
I suspect this is because the op()
needs the full type, but the standard doesn't appear to specify either way.
Which, if either, of these implementations is following standard mandates?
N3936 §17.6.4.8 Other functions [res.on.functions]:
A quick scan through 20.9.3 Class template
reference_wrapper
[refwrap] reveals no such specific exception forreference_wrapper
, so your program has undefined behavior. Both implementations are conforming.