[Bug c++/34749] New: Incorrect warning when applying dllimport to friend function
I was playing with some code and got a warning about dllimport in some headers. I looked around a bit and came up with this test case. The warning seems to imply that dllimport is ignored on bar(), but looking at the output the call to bar() is indeed mangled with __imp prefix. I'm using MinGW g++ 4.2.1-dw2. ## begin df.cpp __attribute__((dllimport)) int bar(); class Foo { private: int foo(); friend __attribute__((dllimport)) int bar(); }; int Foo::foo() { return bar(); } ## end df.cpp D:> g++ -S df.cpp df.cpp:7: warning: 'int bar()' redeclared without dllimport attribute: previous dllimport ignored D:> g++ -v Using built-in specs. Target: mingw32 Configured with: ../gcc-4.2.1-2-src/configure --with-gcc --enable-libgomp --host =mingw32 --build=mingw32 --target=mingw32 --program-suffix=-dw2 --with-arch=i486 --with-tune=generic --disable-werror --prefix=/mingw --with-local-prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c+ +,fortran,objc,obj-c++,ad a --disable-win32-registry --disable-sjlj-exceptions --enable-libstdcxx-debug -- enable-cxx-flags=-fno-function-sections -fno-data-sections --enable-version-spec ific-runtime-libs --disable-bootstrap Thread model: win32 gcc version 4.2.1-dw2 (mingw32-2) -- Summary: Incorrect warning when applying dllimport to friend function Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sldev327 at softmagi dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34749
[Bug c++/34749] Incorrect warning when applying dllimport to friend function
--- Comment #2 from sldev327 at softmagi dot com 2008-01-13 05:52 --- I as well will leave the argument about syntax to more knowledgeable people. As to the validity of this PR, at the very least g++'s behavior is inconsistent.I suppose a case like df3.cpp is what the warning was intended for. g++ warns about __attribute__((dllimport)) not being there on line 7 of df.cpp (when in truth it is), and then goes on to honor it anyway as you can see comparing the output df.s and df3.s. ## begin df3.cpp __attribute__((dllimport)) int bar(); class Foo { private: int foo(); friend int bar(); // dllimport removed }; int Foo::foo() { return bar(); } # end df3.cpp D:> g++ -S df3.cpp df3.cpp:7: warning: 'int bar()' redeclared without dllimport attribute: previous dllimport ignored D:> diff -u df.s df3.s --- df.sSun Jan 13 14:02:58 2008 +++ df3.s Sun Jan 13 14:04:51 2008 @@ -1,4 +1,4 @@ - .file "df.cpp" + .file "df3.cpp" .text .align 2 .globl __ZN3Foo3fooEv @@ -11,8 +11,7 @@ LCFI1: subl$8, %esp LCFI2: - movl__imp___Z3barv, %eax - call*%eax + call__Z3barv leave ret LFE2: @@ -55,3 +54,4 @@ .uleb128 0x5 .align 4 LEFDE1: + .def__Z3barv; .scl2; .type 32; .endef -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34749