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

operator/(duration, duration) cannot be used #555

Open
mtnpke opened this issue Jan 28, 2025 · 1 comment · May be fixed by #557
Open

operator/(duration, duration) cannot be used #555

mtnpke opened this issue Jan 28, 2025 · 1 comment · May be fixed by #557

Comments

@mtnpke
Copy link
Contributor

mtnpke commented Jan 28, 2025

Trying to invoke operator/(duration, duration) yields to compile errors on MSVC because it tries to instantiate the other overload - operator/(duration, number) - and fails in determining the common_type of the arguments. This failure is fatal because EASTL includes the original C++11 common_type definition that is not SFINAE-friendly. This was later acknowledged in N3843 and fixed for C++17 in LWG2408.

(This is irrespective of and a separate issue to #554)

Example code:

seconds s(5);
milliseconds ms(10);
auto result{s / ms}; // added as line 107 in TestChrono.cpp; see below

Error message:

C:\_GIT\EASTL\include\EASTL\internal\type_compound.h(640): error C2446: ':': no conversion from 'T' to 'T'
          with
          [
              T=eastl::chrono::milliseconds
          ]
          and
          [
              T=__int64
          ]
  C:\_GIT\EASTL\include\EASTL/internal/type_compound.h(640): note: the template instantiation context (the oldest one first) is
  C:\_GIT\EASTL\test\source\TestChrono.cpp(107): note: see reference to function template instantiation 'eastl::chrono::duration<eastl::common_type<Rep1,Rep2>::type,Period1> eastl::chrono::operator /(const eastl::chrono::duration<Rep,Period> &,const Rep2 &)' being compiled
  C:\_GIT\EASTL\test\source\TestChrono.cpp(107): note: see reference to class template instantiation 'eastl::common_type<__int64,eastl::chrono::milliseconds>' being compiled
C:\_GIT\EASTL\include\EASTL\internal\type_compound.h(640): error C2062: type 'unknown-type' unexpected
C:\_GIT\EASTL\include\EASTL\internal\type_compound.h(640): error C2238: unexpected token(s) preceding ';'

Compiler version: Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33817 for x64

@mtnpke
Copy link
Contributor Author

mtnpke commented Jan 28, 2025

Further research: While SFINAE seems to fix this problem, the root cause is likely that EASTL is missing an enable_if. The standard says regarding operator/(duration, number): "This operator shall not participate in overload resolution unless Rep2 is implicitly convertible to CR(Rep1, Rep2) and Rep2 is not a specialization of duration." - this is not guarded in EASTL

@mtnpke mtnpke changed the title operator/(duration, duration) cannot be used because common_type is SFINAE-unfriendly operator/(duration, duration) cannot be used Jan 28, 2025
mtnpke added a commit to mtnpke/EASTL that referenced this issue Jan 28, 2025
The division of two durations does not return in a duration, but a plain
number.
Also, the (duration, number) overloads of operator/ and operator%
shall not participate in overload resolution if Rep2 is a duration.

Fixes electronicarts#554, electronicarts#555.
mtnpke added a commit to mtnpke/EASTL that referenced this issue Jan 28, 2025
The (duration, number) overloads of operator/ and operator%
shall not participate in overload resolution if Rep2 is a duration.

Fixes electronicarts#555.
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 a pull request may close this issue.

1 participant