This code works fine with GCC and Clang. It works fine in MSVC when using a custom type instead of std::chrono::duration. It works fine when using an operator+
over operator*
. It works fine with MSVC pre 2018 instead of 2017/2015.
Am I missing anything obvious, or is this just a bug in MSVC? https://godbolt.org/z/EUWV7e
For completeness, here is the test case from the above link:
#include <chrono>
namespace A {
class Foo {
public:
int mCount;
constexpr explicit Foo(int count) : mCount( count ) {}
};
template<class Rep, class Period>
inline Foo
operator*(const Foo foo1, const std::chrono::duration<Rep, Period> duration) {
return Foo(foo1.mCount * duration.count());
}
// For testing purposes, this is identical to operator* above.
template<class Rep, class Period>
inline Foo
operator+(const Foo foo1, const std::chrono::duration<Rep, Period> duration) {
return Foo(foo1.mCount * duration.count());
}
}
int main() {
A::Foo foo1(50);
// This fails to compile for some reason? Changing the '*' to a '+' works fine however.
auto foo2 = foo1 * std::chrono::minutes(15);
return foo2.mCount;
}
I've reported this to the MSVC team at https://developercommunity.visualstudio.com/content/problem/381899/adl-sfinae-bug-in-mvc20152017-when-using-stdchrono.html and they've confirmed it is a bug in MSVC, and has been fixed in the latest release of MSVC2017. Thanks for the discussions!