Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use [[likely]] on AppleClang 12 #274

Merged
merged 1 commit into from
Jan 26, 2023

Conversation

amerry
Copy link
Contributor

@amerry amerry commented Jan 24, 2023

AppleClang 12 doesn't support [[likely]], and warns about an unused
attribute. AppleClang 13 does support [[likely]].

@amerry
Copy link
Contributor Author

amerry commented Jan 25, 2023

It's specifically Xcode 12.5 that this affects, btw. 12.4 and earlier don't pretend to support C++20, and so are caught by the earlier part of the condition.

@BurningEnlightenment
Copy link
Collaborator

I wonder why we don't "just" check

#ifdef __has_cpp_attribute
#if __has_cpp_attribute(likely) && __has_cpp_attribute(unlikely)

according to cppreference __has_cpp_attribute (/P0941) has been implemented on all compilers way before they implemented likely and unlikely support...

@ned14
Copy link
Owner

ned14 commented Jan 25, 2023

I wonder why we don't "just" check according to cppreference __has_cpp_attribute (/P0941) has been implemented on all compilers way before they implemented likely and unlikely support...

I can tell you why: that macro used to be the proprietary markup, and only had C++20 likely and unlikely added late. I remember it arrived via a PR too, somebody really wanted OUTCOME_TRY to mark the branches as likely and unlikely.

How about we use the proper __has_cpp_attribute() in your PR?

All compilers seem to support __has_cpp_attribute before they support
[[likely]], and this is much less error-prone than hard-coding compiler
versions.
@amerry
Copy link
Contributor Author

amerry commented Jan 25, 2023

Makes sense. Checking OUTCOME_TRY_LIKELY_IF twice seemed the cleanest way, give you can't do

#if defined(__has_cpp_attribute) && __has_cpp_attribute(likely)

as that errors if __has_cpp_attribute is not defined

@ned14
Copy link
Owner

ned14 commented Jan 25, 2023

That can be merged when the tests all pass.

Thanks for the BR and providing a fix!

@BurningEnlightenment BurningEnlightenment merged commit 093f364 into ned14:develop Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants