Search code examples
c#c++comcom-interoptlbexp

Properties get renamed when their name is the same as the datatype they return


I am facing the following problem:

My interfaces are defined in C#. I use custom enums in my interfaces. Some of the enums have the same name as the datatype they return, e.g.:

Foo Foo { get; }
Bar Bar { get; }

I use tlbexp to use the module in C++. Properties that share their name with their datatype are renamed from "Name" to "_Name":

Bar myEnumValue = pFoo->Bar // does not exist

Bar myEnumValue = pFoo->_Bar // is my 'Bar'-Property

So far, i did not find any documentation about the reason and if/how i am able to prevent this. I do not get any warnings during build or export.. To make the usage of my module intuitive, I do not want to rename the property or the enum.

Can anyone explain me why this happens?


Solution

  • In C++ this is not allowed:

    class B {};
    class A {
        B B;
    };
    

    because of [basic.scope.class] 3.3.7/1:

    A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule.


    Note that this applies only to declarations inside a class, for namespace scope or function scope the rules are more complicated - sometimes B B; is allowed, sometimes not.


    Update: actually this is perfectly valid:

    class B {};
    class A {
        ::B B;
    };
    

    So you can try to make tlbexp generate code like this.