Why is this code accepted?
nbecker@fred.net
nbecker@fred.net
Mon Apr 16 13:27:00 GMT 2001
This code compiles without complaint both on gcc-2.96 and on a recent gcc-3 snapshot,
but doesn't link. I suspect the initialization of the static "a" is
invalid (I don't have a good reference handy), but isn't gcc behaviour
wrong? If the initialization is invalid, why doesn't the compiler
complain (it doesn't even with -Wall)? If not, why doesn't it link?
--------------------
cd /home/nbecker/bitexact/bitexact/
/opt/gcc/bin/g++ -o bug bug.cc
/tmp/ccZtF0aa.o: In function `X::X() ':
/tmp/ccZtF0aa.o(.gnu.linkonce.t._ZN1XC1Ev+0xa): undefined reference to `X::a '
/tmp/ccZtF0aa.o(.gnu.linkonce.t._ZN1XC1Ev+0xf): undefined reference to `X::a '
collect2: ld returned 1 exit status
--------------------
#include <vector>
using namespace std;
class Y {
vector<double> c;
public:
Y (const double* a, const double* b) :
c (a, b)
{}
};
class X {
static const double a[] = {1, 2};
Y y;
public:
X () :
y (&a[0], &a[2])
{}
};
main () {
vector<X> x (2);
}
-------------------
More information about the Gcc
mailing list