Anonyous unions prevent proper linking.
Karl Nelson
kenelson@ece.ucdavis.edu
Wed Oct 20 01:40:00 GMT 1999
Problem description:
If a class is defined within an anonymous union the functions
within contain the index number of the anonymous union within them.
This number in not unique as it it increments for each class. Thus
if a different number of anonymous unions appear functions will not
link.
Affected platforms and versions:
platforms all, version 2.95
Switchs needed to cause error:
None. Default behavior demonstrate error.
Sample: (This must be in 3 seperate files to demonstrate improper
linking,)
--------------------------test.h--------------------------------
struct A
{
union {
void *v;
struct B {
static void foo();
} b;
};
};
--------------------------test1.cc------------------------------
struct C
{
union {
void *i;
int j;
};
};
#include "test.h"
main()
{
A::B::foo();
}
--------------------------test2.cc------------------------------
#include "test.h"
void A::B::foo() {};
----------------------------------------------------------------
compile with: c++ test1.cc test2.cc
Sample Output:
> c++ test1.cc test2.cc
/tmp/ccftbB1R.o: In function `main':
/tmp/ccftbB1R.o(.text+0x7): undefined reference to `A::._1::B::foo(void)'
collect2: ld returned 1 exit status
A::B::foo is properly defined. This should have linked.
--Karl
More information about the Gcc-bugs
mailing list