limited to a single anonymous class

C

Christopher Bohn

It looks like the c++ source for a single object file can not contain
more than one anonymous class that derives from a base class. When I
attempted to do this, the linker failed with the following error:

fatal error LNK1179: invalid or corrupt file: duplicate COMDAT
'??0__unnamed@@QAE@XZ'

The "??0__unnamed@@QAE@XZ" symbol undecorates to "public: __thiscall
__unnamed::__unnamed(void)" so I think the compiler is using the same
class name for each anonymous class. When the compiler then synthesizes
a default constructor for each class, it winds up generating two
functions with the same name.

Here is some example code:

#include <exception>

class : public exception
{
} anonymous1;

class : public exception
{
} anonymous2;

This was easy to work around by giving each previously anonymous class a
name but shouldn't the compiler generate unique class names for them?
 
V

Vladimir Nesterovsky

Christopher Bohn said:
It looks like the c++ source for a single object file can not contain
more than one anonymous class that derives from a base class. When I
attempted to do this, the linker failed with the following error:

fatal error LNK1179: invalid or corrupt file: duplicate COMDAT
'??0__unnamed@@QAE@XZ'

The "??0__unnamed@@QAE@XZ" symbol undecorates to "public: __thiscall
__unnamed::__unnamed(void)" so I think the compiler is using the same
class name for each anonymous class. When the compiler then synthesizes
a default constructor for each class, it winds up generating two
functions with the same name.

Here is some example code:

#include <exception>

class : public exception
{
} anonymous1;

class : public exception
{
} anonymous2;

This was easy to work around by giving each previously anonymous class a
name but shouldn't the compiler generate unique class names for them?

AFAIK C++ standard only talks about anonymous unions, but not classes and
structures.
Do not expect it's compatible code.
 
C

Carl Daniel [VC++ MVP]

Vladimir said:
AFAIK C++ standard only talks about anonymous unions, but not classes
and structures.
Do not expect it's compatible code.

Actually, it's legal C++ (unfortunately, IMO). Sounds like a legit (if
obscure and unimportant) bug to me.

-cd
 
C

Christopher Bohn

We are using Visual Studio .NET 2003. That doesn't seem to be an option
for a product when filing a bug at the site given below. Is there a way
to file the bug against 2003 or should it be filed under some other
version (even though we haven't tried it under other versions and don't
intend to try the betas from our MSDN subscription)?
 
R

Ronald Laeremans [MSFT]

Hi Christopher,

If you want a fix in 2003 you need to call product support.

If you want it fixed in a future version you can add an entry at that site.
I would be helpful if you can validate it against the Beta of VC 2005, but
not absolutely required. You can mention it in the entry and ask someone to
repro it on VS 2005.

Thanks.

Ronald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top