Visual C++ 10.0 bug in std::reference_wrapper?
Asked Answered
S

1

14

Code:

#include <functional>

struct Foo
{
    virtual void mf() = 0;
};

struct Bar: Foo
{
    virtual void mf() {}
};

int main()
{
    Bar o;
    std::reference_wrapper<Foo const> wrapper( o );
}

Result with MinGW g++ 4.6.1:

[d:\dev\test]
> g++ foo.cpp -std=c++0x

[d:\dev\test]
> _

Result with Visual C++ 10.0:

[d:\dev\test]
> cl foo.cpp
foo.cpp
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
        C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xrefwrap(371) : see reference to class template instantiation 'std::tr1::_Call_wrapper' being compiled
        with
        [
            _Callable=std::tr1::_Callable_obj
        ]
        C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xrefwrap(416) : see reference to class template instantiation 'std::tr1::_Refwrap_impl' being compiled
        with
        [
            _Ty=const Foo
        ]
        foo.cpp(16) : see reference to class template instantiation 'std::tr1::reference_wrapper' being compiled
        with
        [
            _Ty=const Foo
        ]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2027: use of undefined type 'std::
tr1::_Result_of'
        with
        [
            _Ty=const Foo (void)
        ]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(9) : error C2143: syntax error : missing ';' before '('
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class
        due to following members:
        'void Foo::mf(void)' : is abstract
        foo.cpp(5) : see declaration of 'Foo::mf'

[d:\dev\test]
> _

I like the way that the Visual C++ compiler tells the user 11 times that the abstract class cannot be instantiated, just to hammer the point home, like, in case the user was not aware of that. But should std::reference_wrapper really instantiate the class? Is not much of the point of (passing by) reference to not require instantiation?

I.e., is this, as I strongly suspect, a bug in the Visual C++ standard library implementation?

Svetlana answered 29/2, 2012 at 14:7 Comment(6)
I submitted a bug report to Microsoft.Svetlana
Should you not be creating the reference_wrapper with the ref helper function?Perez
@jamesj: no. that's just a helper function, to avoid specifying the type explicitly. in order to investigate a bug it is better to have things explicit than implicit.Svetlana
Microsofts answer to this: "We've already fixed it, and the fix will be available in VC11 RTM. (However, the fix didn't get into the VC11 Beta.)" Wonder what happens with VC10, is there coming another service pack?Fakery
You should answer the question, even if it is yours, and accept it. Not for the rep, but for completion. An answer looks more like an answer than a comment (I wonder why... duh)Masseur
@DavidRodríguez-dribeas, I wonder why. Sites like SO once are channels of communication. When they impose too much of overhead, too much trouble, one just stops using them. Can you imagine anyone intelligent enough to benefit from this, needing the "help" it would be to have an SO "answer"? I think not. :-)Svetlana
A
4

Solved by question author. It is a bug in Visual C++ 10.0 supposedly fixed in the next major version of VC.

Allele answered 29/2, 2012 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.