Mailing-List: contact cygwin-apps-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-apps-owner AT sourceware DOT cygnus DOT com List-Subscribe: List-Archive: List-Post: List-Help: , Delivered-To: mailing list cygwin-apps AT sources DOT redhat DOT com Message-ID: <20010517100006.21057.qmail@web6405.mail.yahoo.com> Date: Thu, 17 May 2001 20:00:06 +1000 (EST) From: =?iso-8859-1?q?Danny=20Smith?= Subject: [PATCH] Don't use context to mark initialised variables as dllimport To: cygwin-apps MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit This is a patch to gcc-2.95.3-4 (cygwin special). Static constant initialisation of data in C++ classes works when linking statically, but not with dllimported classes. The following code is used to build dll: dllclass.h ====================================== #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ class DLLIMPORT DllClass { public: DllClass(); unsigned int a_method () const; static int non_const_int; /* initialised in dllclass.cc */ static const unsigned int const_int=256; char buffer[const_int]; }; ========================================== dllclass.cc =========================================== #include "dllclass.h" #include DllClass::DllClass(){ memset(buffer,0,const_int); } unsigned int DllClass::a_method () const { return const_int; } int DllClass::non_const_int; ============================================ Dll build correctly. non_const_int is exported as DATA. const_int is not exported. That's fine. This is client code: usedll.cc ========================================= #include #include "dllclass.h" int main () { DllClass A; printf("a_method = %d\n", A.a_method()); } ========================================== This fails to compile with error: dllclass.h:13: initialized variable `const int DllClass::const_int' is marked dllimport. This error is emitted by i386_pe_mark_dllimport(), not long after i386_pe_dllimport_p() automatically puts the dllimport there in the first place. In this case, (integral const), one workaround is the enum hack. - static const unsigned int const_int=256; + enum {const_int=256}; The problem occurs because class members get the dllimport status of their class, without first checking if they are initialised inline (eg as for static consts). The following patch to gcc/config/i386/winnt.c fixes the problem. I have tested with STLport, which uses static const initialisation of fmtflags (in ios_base) and locale categories and elsewhere. ChangeLog 2001-05-17 Danny Smith