0

The following code fails to compile in VS2015.

struct Foo
{
    Foo(int value) { }
};

struct Moo
{
    struct
    {
        Foo foo = 0;
    } fooHolder;
};


int main()
{
    Moo moo;
}

The following error is shown.

1>c:\xxx\main.cpp(81): error C2512: 'Foo' : no appropriate default constructor available
1>          This diagnostic occurred in the compiler generated function 'Moo::<unnamed-type-fooHolder>::(void) restrict(cpu, amp)'

If the unnamed struct is given a name, the code compiles.

struct NamedHolder
{
    Foo foo = 0;
} fooHolder;

The code compiled in clang and gcc. http://coliru.stacked-crooked.com/a/3b4ab035a967eed9

Is it rejecting valid code?

typ1232
  • 5,535
  • 6
  • 35
  • 51
  • @101010 I didn't know that. By valid I mean standard compliant. – typ1232 Nov 21 '15 at 16:02
  • I have Visual C++ 2015 00322-20000-00000-AA794 and works fine. – 101010 Nov 21 '15 at 16:08
  • @101010 Do you have the Update 1 RC installed? My version is 00322-90053-68603-AA603. – typ1232 Nov 21 '15 at 16:10
  • @101010 This question hints that unnamed structs are mentioned in the standard: http://stackoverflow.com/questions/14248044/are-anonymous-structs-standard-and-really-what-are-they It also shows the difference to non-standard anonymous structs. – typ1232 Nov 21 '15 at 16:12
  • No I don't have RC installed, furthermore the example compiles in rextester VC++ as well http://rextester.com/XMEP66067. The standard refers only to anonymous unions. – 101010 Nov 21 '15 at 16:16

1 Answers1

1

This code is perfectly fine and it compiles with VS2015 Update 1 RC (just verified). Maybe you're missing something . The system on which I tested :

Microsoft Visual Studio Community 2015

Version 14.0.24627.00 Update 1 RC

Microsoft .NET Framework

Version 4.6.01040

Installed Version: Community

Visual C++ 2015 RC 00322-20000-00000-AA392 Microsoft Visual C++ 2015 RC

...

Community
  • 1
  • 1
Lorah Attkins
  • 5,331
  • 3
  • 29
  • 63