This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/20345] Warning on forward declaration of class with __dllexport__
- From: "vz-gcc at zeitlins dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 16 Oct 2015 23:58:01 +0000
- Subject: [Bug c++/20345] Warning on forward declaration of class with __dllexport__
- Auto-submitted: auto-generated
- References: <bug-20345-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20345
Vadim Zeitlin <vz-gcc at zeitlins dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |vz-gcc at zeitlins dot org
--- Comment #3 from Vadim Zeitlin <vz-gcc at zeitlins dot org> ---
Surprisingly, after all these years I've realized just now that this bug has
never been actually fixed. The patch that was applied fixes the warnings in the
following code:
struct __attribute__((visibility("default"))) S;
struct __attribute__((visibility("default"))) S { };
but it did nothing for this case:
struct __attribute__((visibility("default"))) S { };
struct __attribute__((visibility("default"))) S;
All versions of g++ I have (4.[6789] and 5.2) still give a warning in this
case, e.g. with 5.2.1 and the code above in the file visibility.cpp:
% g++ -Wall -fvisibility=hidden -c visibility.cpp
visibility.cpp:2:47: warning: type attributes ignored after type is already
defined [-Wattributes]
struct __attribute__((visibility("default"))) S;
^
And, of course, while nobody is going to write code like above manually
intentionally, it's pretty common to encounter it in more complicated cases
when various headers forward declare various classes and can be included in
more or less any order. So in practice using visibility attributes in forward
declarations still remains impossible (without getting flooded with warnings,
that is), although it would be very nice for projects adding visibility support
(yes, in 2015, better late than never...) to the existing code which happily
compiles without any warnings using MSVC.
IMO gcc should verify that the class is either not fully declared with a
different visibility instead of just checking that it's not fully declared at
all.