Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the assign-enum warning in clang?

I was going through AFNetworking implementation and I found this

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wassign-enum"
[request setHTTPBody:[NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error]];
#pragma clang diagnostic pop

(AFHTTPClient:489-492)

The assign-enum warning is obviously being turned off, but I wonder what does it mean.

What is the warning thrown by clang in that case?

like image 514
Gabriele Petronella Avatar asked Aug 28 '13 09:08

Gabriele Petronella


1 Answers

The warning emitted in the absence of the clang pragmas is:

Integer constant not in range of enumerated type 'NSJSONWritingOptions' (aka 'enum NSJSONWritingOptions')

Looking at the declaration of NSJSONWritingOptions, we see that there is no defined value for 0:

enum {     NSJSONWritingPrettyPrinted = (1UL << 0) }; typedef NSUInteger NSJSONWritingOptions;

The docs do suggest passing 0, but there is no option defined like NSJSONWritingNoOption = 0, and thus we are assigning a constant (0) to an enum type that doesn't define 0 as a possible value.

like image 72
Carl Veazey Avatar answered Sep 27 '22 01:09

Carl Veazey