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

<type_traits>: Possible improvements of implementation strategy of is_scoped_enum #5333

Open
frederick-vs-ja opened this issue Mar 12, 2025 · 1 comment · May be fixed by #5358
Open

<type_traits>: Possible improvements of implementation strategy of is_scoped_enum #5333

frederick-vs-ja opened this issue Mar 12, 2025 · 1 comment · May be fixed by #5358
Labels
question Further information is requested

Comments

@frederick-vs-ja
Copy link
Contributor

  1. Clang has implemented the __is_scoped_enum intrinsic since Clang 16 (llvm/llvm-project@a089def, LLVM-D135177). But MSVC and EDG don't seem to have it implemented. Should we use __is_scoped_enum for Clang, which possibly improve throughput?
  2. As noticed in <type_traits>: Implement is_scoped_enum #1950, MSVC thinks that an unscoped enumeration type without fixed underlying type is complete in its enumerator-list (and generally treats int as its underlying type). This is non-conforming, while a conformance fix is likely to break the current implementation strategy. I think I've found the strategy (see below) working with both conforming and non-conforming treatments. Should we use it or something similar?
void _Test_convertibility_for_is_scoped_enum(...); // not defined
void _Test_convertibility_for_is_scoped_enum(int) = delete;

template <class _Ty>
concept _Is_scoped_enum_impl = __is_enum(_Ty) && requires { _STD _Test_convertibility_for_is_scoped_enum(_Ty{}); };

_EXPORT_STD template <class _Ty>
struct is_scoped_enum : bool_constant<_Is_scoped_enum_impl<_Ty>> {};

_EXPORT_STD template <class _Ty>
constexpr bool is_scoped_enum_v = _Is_scoped_enum_impl<_Ty>;
@frederick-vs-ja frederick-vs-ja added the question Further information is requested label Mar 12, 2025
@StephanTLavavej
Copy link
Member

I would prefer to get us out of the business of writing increasingly arcane code to implement type traits. So:

  • Using Clang's intrinsic is great.
  • Requesting MSVC and EDG support for Clang's intrinsic would be a good idea.
  • Adding complexity to is_scoped_enum's library-only implementation to handle corner cases involving MSVC non-conformance seems like the wrong direction, and a way to introduce novel bugs. Given that is_scoped_enum hasn't been causing trouble, I don't think we should do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants