When the attached file is compiled with a mingw32 build of GCC 4.3.0, the constructor definition for "foo" does not fully override the declaration in the struct which inherits the dllimport attribute, and a dllimport reference is incorrectly emitted. The member function "bar()" is provided as an example of correctly overriding the dllimport declaration; this issue only occurs with constructors and destructors. Compilation command line and output: > g++ -c impoverride.cpp impoverride.cpp:8: warning: 'foo::foo()' redeclared without dllimport attribute: previous dllimport ignored impoverride.cpp:12: warning: 'void foo::bar()' redeclared without dllimport attr ibute: previous dllimport ignored > nm impoverride.o 00000000 b .bss 00000000 d .data 00000000 t .text 00000011 T __Z3depv 0000000c T __ZN3foo3barEv 00000006 T __ZN3fooC1Ev 00000000 T __ZN3fooC2Ev U __imp___ZN3fooC1Ev << Shouldn't be there! > g++ -v Using built-in specs. Target: mingw32 Configured with: ../../gcc-4.3.0-ehstatic/configure --prefix=/mingw --build=ming w32 --enable-languages=c,c++ --disable-nls --disable-win32-registry --enable-sjl j-exceptions --enable-libgomp --with-gmp=/d/cygdev/gccbuild/libsfor43/debug/gmp- install --with-mpfr=/d/cygdev/gccbuild/libsfor43/debug/mpfr-install --with-libic onv-prefix=/d/cygdev/gccbuild/libsfor43/debug/iconv-install --disable-werror --e nable-threads --enable-libstdcxx-debug --enable-cxx-flags='-fno-function-section s -fno-data-sections' --disable-symvers Thread model: win32 gcc version 4.3.0 (GCC)
Created attachment 15469 [details] Minimal testcase
Note at present, implicit inline within the class definition will work; it's only out-of-line that fails. Also, if we fix this bug in the suggested way, we need to change the documentation to state that the 'inline' is not ignored, and state that this has probably has different behavior from MSVC's dllimport.
Patch at: http://gcc.gnu.org/ml/gcc-patches/2008-04/msg01048.html
Subject: Bug 35921 Author: dannysmith Date: Mon Apr 14 23:53:54 2008 New Revision: 134298 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134298 Log: PR target/35921 * optimize.c (maybe_clone_body): Copy DECL_DLLIMPORT_P flag to clone. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/optimize.c
The issue is fixed for me when applying the mentioned patch to 4.3.0, so as far as I'm concerned we can close this bug as soon as someone applies the fix to 4.3 SVN.
(In reply to comment #5) > The issue is fixed for me when applying the mentioned patch to 4.3.0, so as far > as I'm concerned we can close this bug as soon as someone applies the fix to > 4.3 SVN. > I'll wait a week to see if it causes any problems on trunk, then apply to 4.3 branch. Danny
Created attachment 15702 [details] Minimal testcase for vtable issue I'm not sure whether this is related, but the effect is similar so I'm adding it to this same bug. Basically, we get an undefined reference to the vtable for a dllimport-ed struct with a single inner-defined virtual function. Again, it's something that worked in mingw32 in previous GCC releases and fails in 4.3.0. Command line compilation and output: > g++ -c impoverride2.cpp > nm impoverride2.o 00000000 b .bss 00000000 d .data 00000000 r .rdata$_ZTI3foo 00000000 r .rdata$_ZTS3foo 00000000 r .rdata$_ZTV3foo 00000000 t .text 00000000 t .text$_ZN3foo3barEv 00000000 t .text$_ZN3fooC1Ev 00000000 T __Z3depv 00000000 T __ZN3foo3barEv 00000000 T __ZN3fooC1Ev 00000000 R __ZTI3foo 00000000 R __ZTS3foo 00000000 R __ZTV3foo U __ZTVN10__cxxabiv117__class_type_infoE U __imp___ZTV3foo << Shouldn't be there! > g++ -v Using built-in specs. Target: mingw32 Configured with: ../gcc-4.3.0/configure --prefix=/mingw --build=mingw32 --enable-languages=c,ada,c++,fortran,objc,obj-c++ --with-bugurl=http://www.tdragon.net/recentgcc/bugs.php --disable-nls --disable-win32-registry --enable-libgomp --disable-werror --enable-threads --disable-symvers --enable-cxx-flags='-fno-function-sections -fno-data-sections' --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --program-suffix=-dw2 --with-pkgversion='GCC TDM-3/DW2 for MinGW' Thread model: win32 gcc version 4.3.0-dw2 (GCC TDM-3/DW2 for MinGW)
(In reply to comment #7) > Created an attachment (id=15702) [edit] > Minimal testcase for vtable issue > > I'm not sure whether this is related, but the effect is similar so I'm adding > it to this same bug. > > Basically, we get an undefined reference to the vtable for a dllimport-ed > struct with a single inner-defined virtual function. Uhh, if you declare a struct as dllimport, then you are declaring that it's vtable is defined in a dll. So why is this a bug? Of course if you allow compiler to actually inline the virtual function in your example, the vtable should not be needed. Anyway, thanks for reminding me of this bug. I'll backport 4.4 patch to 4.3.2 once branch reopens. Danny
(In reply to comment #8) > Uhh, if you declare a struct as dllimport, then you are declaring that it's > vtable is defined in a dll. So why is this a bug? Well, it's a change from mingw32/3.4.5's behavior. At any rate, after thinking about it I agree that it isn't a bug. Thanks, John E.
Subject: Bug 35921 Author: dannysmith Date: Sat Jun 7 00:39:43 2008 New Revision: 136515 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136515 Log: PR target/35921 * optimize.c (maybe_clone_body): Copy DECL_DLLIMPORT_P flag to clone. Modified: branches/gcc-4_3-branch/gcc/cp/ChangeLog branches/gcc-4_3-branch/gcc/cp/optimize.c
Fix backported to branch.
*** Bug 36654 has been marked as a duplicate of this bug. ***