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

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 674944 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 6/10/2011 7:21:31 AM
Access Restriction Public


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
	generic<typename TB> where TB : B 
		C<T, TB>^ makeC()
		return gcnew C<T, TB>();
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++.

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)