The following program should fail to link, since <anonymous>::B::x is declared
but not defined.  However, the program compiles, links, and runs with gcc 4.2.1
and with a relatively recent 4.3 snapshot.

This same program fails to build under gcc 4.1 and earlier, icc 8.1, and Comeau
test drive.

struct A {
  A(void *) {}
};

namespace {

struct B : public A {
  B() : A(&x) {}
  static int x;  // declared, but never defined
};

}

int main() {
  B::x = 0;
}


-- 
           Summary: Undefined static data member can acquire a definition
                    anyway
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: simon_baldwin at yahoo dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34094

Reply via email to