Skip to content

Conversation

@vcsjones
Copy link
Member

@vcsjones vcsjones commented Oct 15, 2024

Newer versions of Clang warn when you are doing enum comparisons of different enum types.

Fixes #108827.

Newer versions of Clang warn when you are doing enum comparisons of different enum types.

c_static_assert(PAL_OperationEncrypt == kCCEncrypt);
c_static_assert(PAL_OperationDecrypt == kCCDecrypt);
c_static_assert((uint32_t)PAL_OperationEncrypt == (uint32_t)kCCEncrypt);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the enum types are uint32_t.


*ppDataOut = SecCertificateCopyData(cert);
*pOSStatus = *ppDataOut == NULL ? errSecParam : noErr;
*pOSStatus = *ppDataOut == NULL ? errSecParam : (OSStatus)noErr;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a weird one to me, or the Clang compiler being a little confused. We use noErr all over the place but only complained in this place.

The reason it complains here is it is the only place we don't assign it to some OSStatus as an intermediate, and use it in an expression directly mixing it with an OSStatus. noErr is an anonymous enum in MacTypes.h.

The alternative is to use errSecSuccess. This is functionally the same as noErr (both have a value of 0), but I opted for the smaller change here. It would be a tad weird to use errSecSuccess in this function, but keep using noErr everywhere else, and changing everything seemed unnecessary.

@vcsjones
Copy link
Member Author

With these changes I get a clean build on macOS with Clang 19.1.1.

@vcsjones vcsjones merged commit e9e0ab4 into dotnet:main Oct 15, 2024
97 checks passed
@vcsjones vcsjones deleted the fix-anon-anon-enum-conversion branch October 15, 2024 16:48
@dacheng-gao
Copy link
Contributor

Hey @vcsjones I want to say thank you for the fix.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build error: comparison of different enumeration types

3 participants