user187676
user187676

Reputation:

Controlling Clang Warnings

I've compiled the SQLite amalgamation source into my iOS project, and clang throws a warning on this line

mask = (sizeof(long)==8) ? LARGEST_INT64 : 0x7fffffff;

with the following warning:

Implicit conversion from 'long long' to 'long' changes value from
9223372036854775807 to -1
[warn_impcast_integer_precision_constant]

I've enabled -fdiagnostics-show-name to show the name (warn_impcast_integer_precision_constant).

I certainly don't want to change anything in the SQLite source, since I don't want to introduce unforseen side effects, so I'd like to disable this specific warning just for that one line. The warning is certainly valid, but cannot occur anyway with the sizeof check in place.

To make this process reproducible for other warnings and diagnostics, is there a method to find out the specific warning class and disable them for one line? Unfortunately I can't find anything in the so called clang/llvm "documentation".

Upvotes: 11

Views: 6732

Answers (3)

nido
nido

Reputation: 531

as quoted from the user manual lined by sir Chris Lattner:

In the below example -Wmultichar is ignored for only a single line of code, after which the diagnostics return to whatever state had previously existed.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmultichar"
char b = 'df'; // no warning.
#pragma clang diagnostic pop

But more importantly, would it not be more prudent to consider the type of variable that 'mask' is, and what 'mask' represents?

Since you're doing something depending on whether the size of long is 8, should it perhaps be of type uint64_t?

What if sizeof(long) is actually 16 instead of 8 or 4 (which I guess you expect it to be when it is not 8)? Is 0x7fffffff then still the mask you need? Or perhaps you really want to assign it LONG_MAX from limits.h rather then the current construction.

Upvotes: 1

Chris Lattner
Chris Lattner

Reputation: 829

The clang user manual is here: http://clang.llvm.org/docs/UsersManual.html

It discusses various topics related to diagnostics. There are other useful documents in the sidebar of http://clang.llvm.org/

Upvotes: -1

servn
servn

Reputation: 3069

Any remotely recent version of clang should be printing the flag associated with a given warning along with the warning (in this case -Wconstant-conversion); not sure why you are not seeing this. And to turn it off, you can use #pragma clang diagnostic ignored "-Wconstant-conversion".

Upvotes: 16

Related Questions