Concise way to disable specific warning instances in Clang

两盒软妹~` 提交于 2021-01-24 07:02:50

问题


Suppose there is some warning in my code, e.g. that Clang has added padding to a struct. I am find with that particular instance and I want to mark it as "Noted; don't warn me about this instance again".

Is there a way to do this that isn't insanely verbose (i.e. #pragma clang diagnostic push etc)? Ideally something like a comment on the same line as the warning, something like this:

// clang(-Wno-padded)

To be clear, I only want to suppress one specific instance of the warning (which normally requires #pragma diagnostic push/pop), not all warnings in the file.


回答1:


As described in the Controlling Diagnostics via Pragmas article it would be:

#pragma clang diagnostic ignored "-Wno-padded"

If you want to suppress a warning in a certain chunk of code (be it a single line of code or multiple statements) then you need to utilize the push / pop mechanism:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wno-padded"
// your code for which the warning gets suppressed 
#pragma clang diagnostic pop
// not suppressed here


来源:https://stackoverflow.com/questions/48426484/concise-way-to-disable-specific-warning-instances-in-clang

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