[Bug c++/20345] New: Warning on forward declaration of class with __dllexport__

chicares at cox dot net gcc-bugzilla@gcc.gnu.org
Sun Mar 6 12:07:00 GMT 2005

Forward-declaring a class with a __dllexport__ or __dllimport__
attribute elicits the warning
  "type attributes are honored only at type definition"
even when the same attribute is repeated on the class definition.
Until recently, this usage was accepted with no diagnostic. An
option to inhibit this warning with '-Wall -Wextra' would be welcome,
at least on the ms windows platform (on other platforms, and for
other attributes, this usage may be uncommon or nonexistent).

Unlike the other cases considered in this patch:
here, the meaning is clear; the warning diagnoses only redundancy,
which the 'native' compiler for ms windows documents as permissible:

| You can declare C++ classes with the dllimport or dllexport attribute.

Building a recent cvs snapshot of wxWidgets yields 33673 instances
of this warning with MinGW gcc-3.4.2, but only five other warnings.
One of that library's maintainers states that they added the
redundant declarations throughout because gcc-3.3 required them in
some cases.

How to reproduce:

C:/tmp[0]$cat export_fwd_decl.cpp
class __attribute__((__dllexport__)) E;
class __attribute__((__dllimport__)) I;

class __attribute__((__dllexport__)) E {};
class __attribute__((__dllimport__)) I {};

C:/tmp[0]$/MinGW/bin/g++ -v -save-temps -Wall -Wextra -c export_fwd_decl.cpp
Reading specs from /MinGW/bin/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --e
nable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-ja
va-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchroniz
ation --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)
 /MinGW/bin/../libexec/gcc/mingw32/3.4.2/cc1plus.exe -E -quiet -v -iprefix \MinG
W\bin\../lib/gcc/mingw32/3.4.2/ export_fwd_decl.cpp -Wall -Wextra -o export_fwd_
ignoring nonexistent directory "/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/3.4.2/../../../../mingw32
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /MinGW/bin/../libexec/gcc/mingw32/3.4.2/cc1plus.exe -fpreprocessed export_fwd_d
ecl.ii -quiet -dumpbase export_fwd_decl.cpp -auxbase export_fwd_decl -Wall -Wext
ra -version -o export_fwd_decl.s
GNU C++ version 3.4.2 (mingw-special) (mingw32)
        compiled by GNU C version 3.4.2 (mingw-special).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=130943
export_fwd_decl.cpp:1: warning: type attributes are honored only at type definit
export_fwd_decl.cpp:2: warning: type attributes are honored only at type definit
 /MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/bin/as.exe -o export_fw
d_decl.o export_fwd_decl.s
C:/tmp[0]$cat export_fwd_decl.i*
# 1 "export_fwd_decl.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "export_fwd_decl.cpp"
class __attribute__((__dllexport__)) E;
class __attribute__((__dllimport__)) I;

class __attribute__((__dllexport__)) E {};
class __attribute__((__dllimport__)) I {};

           Summary: Warning on forward declaration of class with
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chicares at cox dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-mingw32
  GCC host triplet: i686-pc-mingw32
GCC target triplet: i686-pc-mingw32


More information about the Gcc-bugs mailing list