I've something such as this during my code:

#include <iostream>

#include <cstdlib>

struct Base

struct Child


  struct : public Base



int primary()

I'd expect this to provide this output:

ble: 1

ble: 2

also it achieves this, when put together under GCC (3.4.5 In my opinion).

Producing and running this under Visual Studio 2008 however, gives this:

ble: 2

ble: 2

What's interesting, is when I provide the Base-derived structs names (struct s1 : public Base), it really works properly.

Which behavior, if any, is correct? Is Versus just being prissy, or perhaps is it sticking towards the standard? Am I missing something vital here?

It seems this can be a bug in Versus 2008, possibly since it overwrites or ignores the vtable for that first un named class in support of the vtable for that second because the internal names are the same. (Whenever you title one clearly, the interior names for that vtables are no more identical.)

So far as I will tell in the standard, this will act as you anticipate and gcc is appropriate.

It's visible how MSVC is setting it up wrong in the debugging symbols. It creates temporary names for that anonymous structs, correspondingly Child::<unnamed-type-First> and Child::<unnamed-type-Second>. There's however just one vtable, it's named Child::<unnamed-tag>::'vftable' and both constructors utilize it. The various reputation for the vtable is surely area of the bug.

You will find several bugs reported at connection.microsoft.com that are based on anonymous types, none which ever managed to get to "must-fix" status. Not the main one you found though, afaict. Maybe the workaround is simply too simple.

I'm able to confirm this can be a known bug within the VC compiler (also it repos in VC10) the 2 anonymous courses are improperly discussing a vtable.

Anonymous structs are not area of the C++ standard.

Edit: Anonymous structs are type of an ambiguous term. It may mean a couple of things:

class outer

 m_a // 1

    struct      // 2

    union      // 3

1 is what's going on here, a much better title than anonymous struct could be "un named struct". The struct type itself does not possess a title, however the object does (m_a).

2 is also called an anonymous struct, and is not legal C++. There's no object title, and also the idea is that you simply could access the area 'c' on objects of type outer. This compiles only due to a compiler extension in Visual Studio (will fail under /Za)

3 Anonymous unions, by comparison, are legal C++.

I confused the 2, because here we are calling #1 an "anonymous struct", and wires during my brain entered with #2.