问题
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