This depends on your usage of unions, especially on how scattered over your code the union usage mentioned in your question is.
If you use it all over the place there's not much you can do apart from disabling the check.
If it's constrained to several specific places you can use the -line-filter
option to filter out files (or even lines) where this is used. The tricky part is that -line-filter
filters lines IN.
This filters out all warnings from unions.cpp
(assuming it has less than 9999999 lines):
-line-filter=[{"name":"unions.cpp","lines":[[9999999,9999999]]},{"name":".h"},{"name":".cpp"}]
{"name":".h"},{"name":".cpp"}
filters in the rest of the files, otherwise you would see no warnings at all.
Alternately if you would like only to filter out some lines from unions.cpp
:
-line-filter=[{"name":"unions.cpp","lines":[[1,10],[12,100]]}},{"name":".h"},{"name":".cpp"}]
Line 11 will be skipped in this example.
Obviously this would filter out warnings for all checks from that file (or lines) so you may want to run that check separately.