禁用Clang中特定警告实例的简便方法 [英] Concise way to disable specific warning instances in Clang
问题描述
假设我的代码中有一些警告,例如Clang已将填充添加到结构中.我发现有该特定实例,我想将其标记为已注意到;不要再对这个实例发出警告".
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".
有没有办法做到这一点呢(不是 #pragma clang诊断推送
等)?理想情况下,在警告的同一行中有类似注释的内容,例如:
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)
要清楚,我只想抑制警告的一个特定实例(通常需要 #pragma诊断推送
/ pop
),而不是文件中的所有警告.
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.
推荐答案
如通过Pragmas控制诊断文章应该是:
#pragma clang diagnostic ignored "-Wno-padded"
如果要在特定代码段(单行代码或多条语句)中禁止显示警告,则需要利用 push
/ pop
机制:
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
这篇关于禁用Clang中特定警告实例的简便方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!