From: Danny S. <dan...@cl...> - 2005-02-21 05:58:41
|
Greg Chicares wrote: > Building a cvs snapshot of wxWidgets produces many warnings > with MinGW gcc-3.4.2 (their makefile uses '-W'): > > C:/wx-cvs-20050216/wxWidgets/build/msw[0]$ \ > grep "type attributes are honored only at type definition" \ > buildlog |wc -l > 33673 > > Without that diagnostic and its attendant "In file included from" > output, the output would be only about 500 lines long. Yet the > warning is benign in this case. Is there a way to turn off this > specific warning, while still using '-W'? If not, should there be? Hello Greg In FSF sources, the warning is also emitted with just -Wall. Downgrading the warning to a -Wextra is a local patch. > > Admittedly coming to the party rather late, and reading > http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01004.html > now, I wonder whether one more case should be distinguished: > > // Case 2a: > // Forward declaration with DLLEXPORT attribute > // followed by definition with DLLEXPORT attribute repeated. > > struct __attribute__((__dllexport__)) Foo2a; // WARNING HERE > struct __attribute__((__dllexport__)) Bar2a; // WARNING HERE > > struct __attribute__((__dllexport__)) Bar2a > { > int useFoo2a (const Foo2a&); > }; > > struct __attribute__((__dllexport__)) Foo2a > { > int foo2a_fun(void) const; > }; > > int Bar2a::useFoo2a(const Foo2a& _x) > { > return _x.foo2a_fun(); > } > > void test2a() > { > Bar2a aBar2a; > Foo2a aFoo2a; > aBar2a.useFoo2a (aFoo2a); > } > > That differs from the original "Case2" in two ways: > - the attribute is on both the declaration and the definition > - dllexport instead of dllimport (it makes less sense to import > a class and then define a member function out of line) > > That's the way wxWidgets is written, and I imagine that some > compiler they support wants it that way. MSDN says it's OK: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pl uslang_using_dllimport_and_dllexport_in_c.2b2b.asp >> You can declare C++ classes with the dllimport or dllexport attribute. > > The case in favor of selectively turning this warning off > so that "Case2a" would compile without warnings: > - it's an established usage, condoned by MSDN > - it's a best practice to strive for clean builds with as > many warnings enabled as possible > - omitting '-W' turns off many other warnings that are valuable > - detecting this case, where a forward declaration happens > not to conflict with a later definition, is probably hard; > instead of having the parser look ahead for the definition, > just let a user say "I know what I'm doing" > > The case against is that there are already many flags to enable > and disable particular warnings, and they shouldn't be allowed > to proliferate endlessly. This seems to be of concern only for > the windows platform at present, although when this attribute > is adapted for "visibility", a specific warning-suppression flag > may become more generally handy. Another reason against this is > that if you turn off this warning, but don't put the seemingly > redundant attribute on the class definition, then things won't > work as you expect (but I guess that's like all sharp tools). > > Probably there are other pros and cons that I'm missing. > Is this the right place to discuss this? > Probaly the best place is in GCC's bugzilla.. The place where the warning is emitted is not specific to dllexport/dllimport, but affects all type atributes (i0e aligned, packed). Only windows code seems to be in the habit of adding attributes to forward declarations of user defined types. I once tried to avoid these warnings by changing windows specific code for handling dllimport/dllexport. I can't remember why I stopped try.ing Now, that code is in the generic backend. I'll look again. Perhaps -fms-extensions should disable this warning for dllexport attribute on classes. Danny > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users |