Search

Public Parameterless Constructor Not Found in VC++ by hasenpfeffer2

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 676125
Opened: 6/20/2011 9:24:48 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
1
User(s) can reproduce this bug
The Visual C++ compiler is unable to find a public parameterless constructor when attempting to externally consume a class that references itself within multiple generics. The error does not appear using C#. The class library builds successfully. Visual C++ app results in a C3392 error, while C# app builds successfully.

I have been unable to figure out a workaround.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010

Steps to reproduce

3 projects are defined. A class library using VC++, a console app using VC++, and a console app using C#. Both console apps reference the class library.

Class Library "test" contains a single useful file, test.h:
// test.h

#pragma once

namespace A
{

    generic<typename T>
    where T : gcnew()
    public ref class A
    {
    public:
        A() { }
    };

    generic<typename T>
    where T : gcnew()
    public ref class B : System::IComparable<B<T>^>
    {
    public:
        B() { }
        virtual int CompareTo(B<T>^ other) { return 0; }
    };

    public ref class C
    {
    public:
        C() { }
        property A<B<C^>^>^ p { A<B<C^>^>^ get() { return nullptr; } }
    };

}

VC++ console app contains a single useful file, cppapp.cpp:
// cppapp.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
    A::C^ f = gcnew A::C();
    Console::WriteLine(L"Hello World");
    return 0;
}

C# console app contains a single useful file, Program.cs:
using System;
using System.Collections.Generic;
using System.Text;

namespace csapp
{
    class Program
    {
        static void Main(string[] args)
        {
            A.C f = new A.C();
        }
    }
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

1>------ Rebuild All started: Project: test, Configuration: Debug Win32 ------
1> Stdafx.cpp
1> AssemblyInfo.cpp
1> test.cpp
1> Generating Code...
1> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
1> test.vcxproj -> C:\src\test\Debug\test.dll
2>------ Rebuild All started: Project: cppapp, Configuration: Debug Win32 ------
3>------ Rebuild All started: Project: csapp, Configuration: Debug Any CPU ------
3> csapp -> C:\src\test\csapp\bin\Debug\csapp.exe
2> stdafx.cpp
2> AssemblyInfo.cpp
2> cppapp.cpp
2>cppapp.cpp(9): error C3392: 'A::C ^' : invalid type argument for generic parameter 'T' of generic 'A::B', must have a public parameterless constructor
2>         c:\src\test\debug\test.dll : see declaration of 'A::B'
2>         cppapp.cpp(9) : see reference to class generic instantiation 'A::B<T>' being compiled
2>         with
2>         [
2>             T=A::C ^
2>         ]
2>         This diagnostic occurred while importing type 'A::C ' from assembly 'test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
2>cppapp.cpp(9): error C3392: 'A::C ^' : invalid type argument for generic parameter 'T' of generic 'A::B', must have a public parameterless constructor
2>         c:\src\test\debug\test.dll : see declaration of 'A::B'
2>         This diagnostic occurred while importing type 'A::C ' from assembly 'test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
2> Generating Code...
========== Rebuild All: 2 succeeded, 1 failed, 0 skipped ==========

Expected results

Successful build.
File Attachments
File Name Submitted By Submitted On File Size  
test.zip 6/20/2011 45 KB
Sign in to post a comment.
Posted by Microsoft on 9/20/2011 at 3:20 PM
Hi: this issue has been fixed. The fix should show up in a future release of Visual C++.

Thank you for reporting the issue.

Jonathan Caves
Visual C++ Compiler Team
Posted by hasenpfeffer2 on 6/21/2011 at 9:56 AM
Using getter/setter methods directly in place of the property 'p' does seem to work around the issue. I tried this technique in my actual project with successful results. Thanks. This isn't preferred, but should allow me to move forward.
Posted by MS-Moderator10 [Feedback Moderator] on 6/20/2011 at 6:49 PM
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 MS-Moderator01 on 6/20/2011 at 9: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.
Posted by Viorel_ on 6/21/2011 at 1:33 AM
Consider an ordinary getter instead of property 'p':

    public ref class C
    {
    public:
        C() { }

        A<B<C^>^>^ get() { return nullptr; }
    };