Home Dashboard Directory Help
Search

C++/CLI compiler gives error C3214 when invoking a class with generic constraint by Tom Minka


Status: 

Closed
 as Fixed Help for as Fixed


2
0
Sign in
to vote
Type: Bug
ID: 674944
Opened: 6/10/2011 7:21:31 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

If you make a C# assembly with the following code:

    public class B
    {
    }
    public class C<T, TB>
        where TB : B
    {
    }
    public class A<T>
    {
        public C<T, TB> makeC<TB>()
            where TB : B
        {
            return new C<T, TB>();
        }
    }

Then make a C++/CLI project that references the previous one and has the following code:

A<bool>^ x = gcnew A<bool>();

The result is:

error C3214: 'TB' : invalid type argument for generic parameter 'TB' of generic 'C', does not meet constraint 'B ^'

This error message should not be there. Interestingly, if the code is written entirely in C# or entirely in C++ (in a single source file), then no error message is generated. Update: If you define classes A,B,C in a C++/CLI assembly instead of C#, then the error message is still generated. So the issue is not about C# but rather referencing any assembly that defines classes A,B,C in the above manner. Here is the analogous C++ code:

public ref class B {};
generic<typename T,typename TB> where TB : B public ref class C {};
generic<typename T>    public ref class A
{
public:
    generic<typename TB> where TB : B
        C<T, TB>^ makeC()
    {
        return gcnew C<T, TB>();
    }
};
Details
Sign in to post a comment.
Posted by Microsoft on 3/15/2012 at 5:55 PM
Hi: a fix for this issue has been checked into the C++ compiler. The fix should show up in the next release of the Visual C++.

Thanks
Jonathan Caves
Visual C++ Compiler Team
Posted by MS-Moderator10 [Feedback Moderator] on 6/13/2011 at 12:35 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 6/10/2011 at 7:49 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)
Sign in to post a workaround.