This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Why is this code accepted?
- To: gcc at gcc dot gnu dot org
- Subject: Why is this code accepted?
- From: nbecker at fred dot net
- Date: 16 Apr 2001 16:27:42 -0400
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);
}
-------------------