Search

C++ CLI property overriding and renaming by Richard78

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 651255
Opened: 3/14/2011 2:04:17 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
Hello,

I'm using Visual Studio 2010 and .NET4.0.

I have the following classes defined in a dll (simplification of my real code):

namespace test {

interface class I
{
property bool IsOk
{
bool get();
}
};

public ref class A abstract : I
{
private:
virtual property bool IsFine
{
bool get() sealed = I::IsOk::get
{
    return false;
}
}
};


//OK
public ref class B : public A
{

};

}

The code compiles. But if I define a new class deriving from A in another dll or exe



ref class C : public test::A
{

};



I get some compilation warnings and errors which do not make any senses to me:

    * error C3766: 'C' must provide an implementation for the interface method 'bool test::I::IsOk::get(void)' see declaration of 'test::I::IsOk::get'

    * warning C4570: 'C' : is not explicitly declared as abstract but has abstract functions 'bool test::I::IsOk::get(void)' : is abstract see declaration of 'test::I::IsOk::get'

    * error C2259: 'C' : cannot instantiate abstract class due to following members: 'bool test::I::IsOk::get(void)' : is abstract deleteme3.cpp(36) : see declaration of 'test::I::IsOk::get'



There are no differences between the classes 'B' and 'C'.

If now I define the same class 'C' in a C# project, I have no compilation error or warnings.



I have checked the IL for the class A:

.method private hidebysig newslot specialname virtual final
    instance bool
    marshal( unsigned int8)
    get_IsFine() cil managed
{
.override test.I::get_IsOk
// Code size    4 (0x4)
.maxstack 1
.locals ([0] bool V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldloc.0
IL_0003: ret
} // end of method A::get_IsFine

I can see the override information. I wonder if the compiler simply ignore this information when it reads my reference, or do I miss something in my code?



Regards,

Richard
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

Define the following classes and interfaces in a dll:
namespace test {

interface class I
{
property bool IsOk
{
bool get();
}
};

public ref class A abstract : I
{
private:
virtual property bool IsFine
{
bool get() sealed = I::IsOk::get
{
    return false;
}
}
};

define the following class in another dll and compile everything

ref class C : public test::A
{

};

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

Compilation errors and warnings:


    * error C3766: 'C' must provide an implementation for the interface method 'bool test::I::IsOk::get(void)' see declaration of 'test::I::IsOk::get'

    * warning C4570: 'C' : is not explicitly declared as abstract but has abstract functions 'bool test::I::IsOk::get(void)' : is abstract see declaration of 'test::I::IsOk::get'

    * error C2259: 'C' : cannot instantiate abstract class due to following members: 'bool test::I::IsOk::get(void)' : is abstract deleteme3.cpp(36) : see declaration of 'test::I::IsOk::get'

Expected results

No errors and no warnings
File Attachments
File Name Submitted By Submitted On File Size  
Bug651255.zip 3/14/2011 15 KB
Bug651255.zip 3/14/2011 15 KB
Sign in to post a comment.
Posted by Microsoft on 4/18/2011 at 8:57 AM
Hi Richard:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by Microsoft on 3/21/2011 at 6:56 PM
Hello Richard,

Thank you for reporting this bug. This indeed is a bug in our compiler where we're failing to look at .override directive for explicit named overrides in abstract classes. So, you're right in your diagnosis. We'll consider fixing this in a future release. In the meantime, please accept these workarounds.

1) If class A doesn't have to be abstract, then please make non-abstract. Bug goes away.
2) If named override is needed (like you have another IsOk function that needed to be declared in A), then here's a trickery you can use to fool the compiler into looking at .override directives.
namespace test {

    public interface class I
    {
        property bool IsOk
        {
            bool get();
        }
    };
#pragma warning (disable:4483)
    public ref class A abstract : I
    {
    public:
        virtual property bool __identifier("I.IsOk")
        {
            bool get() sealed = I::IsOk::get
            {
                return false;
            }
        }
    };


}

Thanks,
Ulzii Luvsanbat
Windows C++ Team
Posted by Microsoft on 3/17/2011 at 12:47 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 3/14/2011 at 2:13 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Microsoft on 3/14/2011 at 2:12 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

Please submit this information to us within 4 business days. We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Sign in to post a workaround.