5 ms·
How do you deal with thirdparty includes, particularly with big header-only libraries? You basically have to change compiler flags on the fly, and AFAIK it isn'
by ansgri 9y ago
How do you deal with thirdparty includes, particularly with big header-only libraries? You basically have to change compiler flags on the fly, and AFAIK it isn't well supported. My colleagues have dealt with this by defining some ugly macros which enable/disable hardcoded warnings, and there are lots of them.
- humanrebar 9y agoI've had good success including not-my-code with the appropriate compiler flag. This tells the compiler that I'm not interested in warnings in those files since I'm not going to change them. https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html
- ansgri 9y agoThanks, this looks like a better solution!
- wfunction 9y agoHow does this work with templates? If a type you pass into such a library causes a warning in that library, is that your fault or the library's? How could the compiler possibly tell? It seems like this can't even work in principle if there are templates involved.
- humanrebar 9y agoThe warnings I've had issues with were warnings regardless of whether the code was templates: ignored return values, unused parameters, etc. There may be cases where the potential false negatives are unacceptable. Be judicious, but in my case the benefits far outweighed the risks. Of course, it's a great idea to provide upstream patches and issues whenever possible.
- jcoffland 9y agoThat's good to know. I usually just add a warning suppression or two.
- akavel 9y agoCan't you do it just with some #pragmas?
- andreyv 9y agoWith GCC and Clang, you should use -isystem<thirdparty/header/dir> instead of -I<thirdparty/header/dir> for these include directories. This will suppress warnings from these headers. CMake also supports this through include_directories(SYSTEM …). With MSVC you will have to fall back on macros.
- ensiferum 9y agoMake a warnpush.h file where you use compiler pragmas to suppress warnings and then make a warnpop.h file to restore. Then you do #include "warnpush.h" #include <crappy.h> #include "warnpop.h" I always do this for third party headers in my projects. Except for std headers. Example: https://github.com/ensisoft/newsflash-plus/blob/master/app/commands.h#L25 https://github.com/ensisoft/newsflash-plus/blob/master/app/c...
- jcoffland 9y agoHere's what's in warnpush.h: https://github.com/ensisoft/newsflash-plus/blob/master/newsflash/warnpush.h https://github.com/ensisoft/newsflash-plus/blob/master/newsf...
- ansgri 9y agoHeh, an analogous file in my colleagues' project is 250 non-emply LOC. It seems to list every warning for GCC from 4.8 to 6.X. Sorry, not open source (yet?).
- fest 9y agoIf the number of distinct warnings is small, I tend to fix them and submit a PR.