CGEventFlags (and the like) should not be a strong enum

Originator:peter
Number:rdar://25520516 Date Originated:04-Apr-2016 10:12 AM
Status:Closed Resolved:Fixed in 10.12/XCode 8
Product:OS X SDK Product Version:SDK 10.11
Classification:Usability Reproducible:Always
 
Summary:
Since you need to do bitwise operations on it, using CGEventFlags when it is defined as a strong enum becomes basically impossible.

Even conceptually it does not make much sense, the type is specifically designed to hold bitwise flags, not just the specific enumerated values listed.

There is not even any "no flags" constant defined.

Trying to use CGEventFlags in code with strong enums is a complete nightmare.  Try implementing code like:

CGEventFlags ef = 0;
if ( test ) {
  ef |= kCGEventFlagMaskShift;
}
CGEventSetFlags( keyEvent, ef );

The first line fails because 0 is not valid, and the third line fails because you can't do bitwise operations on enums.

If you instead use std::underlying_type<CGEventFlags>::type, then you are left casting it back for every call to the OS.

It is extremely ugly and inappropriate use of a strong enum - I'm sure there are other Flag cases as well which should not be strong enums.

Steps to Reproduce:


Expected Results:


Actual Results:


Version:
Xcode 7.3, OS X 10.11.4

Notes:


Configuration:


Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!