Is is possible to disable this warning in clang? warning: #pragma once in main file

烈酒焚心 提交于 2019-12-06 17:10:56

问题


warning: #pragma once in main file

We're running our headers through clang to get a partial AST.

Is it possible to disable that warning?


回答1:


Use the -Wno-pragma-once-outside-header command line argument. Consult the Clang documentation here.




回答2:


I had this thing when I accidentally included a header file in compile sources (this header has #pragma once line). To fix this remove header from compile sources (and probably you need to replace it with .cpp file)




回答3:


There's no -W option for "#pragma once in main file", so you can't turn it off via the usual means. (However, the Clang developers are very aware that warnings without -W options suck, and there's a general rule that new warnings always get -W options. Cleaning up the old code, unfortunately, is left as an exercise for frustrated users.)

If you don't mind shell hackery, you could always do something like this:

# This gives the warning...
clang -c myheader.h

# ...This doesn't.
echo '#include "myheader.h"' | clang -c -x c++-header -o myheader.h.gch -

The trailing -, as usual, means "read from stdin". The -x c++ tells Clang what language you're using (since it can't tell from the file extension when there is no file), and changing c++ to c++-header means that we want to produce a .gch file instead of an .o file.

The two .gch files thus produced are NOT bit-for-bit identical. I don't know enough about gch files to tell you what might be observably different about their behavior. However, since all you care about is Clang's AST, I bet you'll be fine with it. :)




回答4:


Use the -w (lowercase w not uppercase W) option while compiling the source to suppress such warnings.




回答5:


There are no option to control it, so just ban this warning in your code.



来源:https://stackoverflow.com/questions/16726352/is-is-possible-to-disable-this-warning-in-clang-warning-pragma-once-in-main-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!