Bug 14347 - mcs doesn't generate CS0208 on pointers to type parameters
Summary: mcs doesn't generate CS0208 on pointers to type parameters
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2013-08-30 10:32 UTC by Jonathan Pryor
Modified: 2013-08-30 11:51 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jonathan Pryor 2013-08-30 10:32:37 UTC
Consider the following code:

  unsafe class Foo<T>
    where T : struct
    public T* Elements {get {return null;}}

  class Test {
    public static unsafe void Main ()

mcs compiles it without errors.

.NET CSC errors with:

gp.cs(6,12): error CS0208: Cannot take the address of, get the size of, or
        declare a pointer to a managed type ('T')

(If `where T : struct` is removed, mcs generates the correct error.)

Furthermore, when attempting to use Foo<T>, mcs errors with CS0584/NotSupportedException:

    var f = new Foo<int>();
$ mcs /unsafe gp.cs --stacktrace
gp.cs(10,15): error CS0584: Internal compiler error: Operation is not supported.
	in Expression.Resolve (Mono.CSharp.ResolveContext, Mono.CSharp.ResolveFlags)
	in Expression.Resolve (Mono.CSharp.ResolveContext)
	in BlockVariable.Resolve (Mono.CSharp.BlockContext, System.Boolean)
	in BlockVariable.Resolve (Mono.CSharp.BlockContext)
	in Block.Resolve (Mono.CSharp.BlockContext)
	in ParametersBlock.Resolve (Mono.CSharp.FlowBranching, Mono.CSharp.BlockContext, Mono.CSharp.IMethodData)
	in MethodData.Emit (Mono.CSharp.TypeDefinition)
	in MethodOrOperator.Emit ()
	in Method.Emit ()
	in TypeDefinition.Emit ()
	in ClassOrStruct.Emit ()
	in Class.Emit ()
	in TypeDefinition.EmitContainer ()
	in TypeContainer.EmitContainer ()
	in NamespaceContainer.EmitContainer ()
	in TypeContainer.EmitContainer ()
	in ModuleContainer.EmitContainer ()
	in AssemblyDefinition.Emit ()
	in AssemblyDefinitionStatic.Emit ()
	in Driver.Compile ()
	in Driver.Main (System.String[])
Comment 1 Marek Safar 2013-08-30 11:51:07 UTC
Fixed in master