Created
November 4, 2013 12:49
-
-
Save simonwhitaker/7301972 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
typedef NS_OPTIONS(uint32_t, SomeOption) { | |
SomeOptionNone = 0, | |
SomeOptionFoo = 1 << 0, | |
SomeOptionBar = 1 << 1, | |
}; | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
SomeOption o = SomeOptionFoo|SomeOptionBar; | |
NSLog(@"o = %u", o); | |
} | |
} |
So it seems to be a definite this value doesn't exist in the enum list warning.
For example if we add to Simon's example:
typedef NS_OPTIONS(uint32_t, SomeOption) {
SomeOptionNone = 0,
SomeOptionFoo = 1 << 0,
SomeOptionBar = 1 << 1,
SomeOptionBaz = 1 << 2,
SomeOptionAll = (SomeOptionBar | SomeOptionFoo | SomeOptionBaz)
};
doing:
SomeOption option = (SomeOptionBar | SomeOptionFoo | SomeOptionBaz);
is fine, while
SomeOption option = (SomeOptionBar | SomeOptionFoo);
yields the same warning as before.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I imagine that it ought to, as I'm assuming that the warning is really saying "that value is bigger than the biggest enum value you've declared".
It looks like NS_OPTION (and CF_OPTION) just declare the options as a typed enum, so there's no way for the compiler to know that it is valid to combine the values.
So all it could conceivably warn about is that the value of an assignment is larger than the largest enum value you defined.
It would probably require some sort of __option to be added to Clang to do more.