Pergunta

Normalmente, gosto de ter muitos avisos ativados ao programar. No entanto, algumas bibliotecas contêm código que causa facilmente avisos (.., python, qt, ..). Ao compilar com o GCC, posso usar -Isystem em vez de -i para silenciar isso. Como posso fazer o mesmo com o compilador MS? Conheço o aviso #pragma, mas gostaria de uma solução que não envolva código específico do compilador em todo o lugar. Eu também sei que posso desligar avisos específicos, mas também não é isso que eu quero.

BTW: Isystem deve ser uma etiqueta dessa pergunta, mas eu não tinha permissão para fazer isso ..

Resumo: Eu quero ver tudo avisos do meu código e não avisos do código externo.

Foi útil?

Solução

As of 2017-08-17 this still seems impossible.

I added a feature request here:

https://developercommunity.visualstudio.com/content/problem/96411/impossible-to-ignore-warnings-from-system-librarie.html

Update 2018:

The issue is now closed as fixed and is available in the standard MS VS installation [source]. A blog post from the MS team goes through the new features [here].

The solution from MS is flexible. You can not only differentiate using paths like you do with --isystem, but for example also by whether you use #include "" or #include <>. The blog post is worth a read to see all the various customization points.

Finally warnings are usable for me also on the MS VS platform.

Outras dicas

This now exists under /experimental:external /external:I system_include_path /external:W0. See https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/ for many more details.

No, MSVC doesn't have an -isystem equivalent.


look at the output output from cl /? :

/wd disable warning n

/we treat warning n as an error

/wo issue warning n once

/w set warning level 1-4 for n

Note that this disables the warnings for your entire project; I remember when using Qt I'd rather change it's main header with the #pragma warning disable and enable at the end again so I could still see all warnings for my own source.

Edit the author edited his question, updated answer: there is no way to get your code with warnings and Qt code without warnings using compiler flags: how are you going to tell the compiler what is 'your' code?

Note that the above flags can be applied at file level as well, so this would allow you to disable the warnings for only those files in which you include Qt headers, but that still means you cannot see them for your own code in that files.

So I stay with the answer above; it is not quite pretty, but I'm pretty sure it's the only way: use #pragma at the beginning and the end of the Qt header(s). Either change the Qt headers (even more ugly), or choose a less invasive way like this:

//your source/header file
#include "shutuppqt.h"
#include <QString>
#include "enableallwarnings.h"

example "shutuppqt.h"

#ifdef MSVC
  #pragma warning ( disable : 4222 ) //or whatever warning Qt emits
#else
  //....
#endif

example "enableallwarnings.h"

#ifdef MSVC
  #pragma warning ( enable : 4222 ) //or default instead of enable
#else
  //....
#endif
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top