Closed chris-se closed 2 years ago
Is there a reason why the size-based dispatching introduced in the initial commit didn't work properly on AVR so that it had to be dropped for that?
The AVR tool chain does not ship with a Standard Library, so no <type_traits>
header.
I've reproduced the compile failure on Windows x64:
// Issue #96: https://github.com/ridiculousfish/libdivide/issues/96
libdivide::divider<short> short_div{42};
libdivide::divider<int> int_div{42};
libdivide::divider<long> long_div{42};
libdivide::divider<long long> long_long_div{42};
libdivide::divider<std::ptrdiff_t> ptr_diff_div{42};
Other than a compile test is there something else to test for?
Ah, the lack of <type_traits>
makes a lot of sense. (Though it's a bit unfortunate that they don't ship the bits of the STL that have zero runtime overhead.)
Other than a compile test is there something else to test for?
No, it either compiles and everything is fine, or it doesn't, and you immediately notice that. Your test for short
/int
/long
/long long
is perfectly sufficient here, because on all relevant platforms at least two of those types will have the same size and trigger this issue. (Though which two will vary.)
Many thanks for the extremely quick response and the fix!
Also just tested your patch against v5.0 of libdivide and it works perfectly. Thanks!
With commit https://github.com/ridiculousfish/libdivide/commit/623f9be3e406712be192e75833019f790aef8a51 support was added to make size_t work on some platforms, notably macOS.
This broke again with this commit: https://github.com/ridiculousfish/libdivide/commit/10ba9826646625101397c1203a9ca2622f14eba6
This is a regression in a codebase I'm working on when compiling on macOS, because it causes a compiler error in the following code:
libdivide::divider<std::ptrdiff_t> v{42};
This is because
int64_t
is aliased tolong long
on macOS, whileptrdiff_t
is aliased tolong
(andsize_t
tounsigned long
, whileuint64_t
is aliased tounsigned long long
). And while bothlong
andlong long
behave identically in that case, they are not the same type in the C++ type system, so there is no correct template that can be selected by the compiler for thelibdivide::divider
class.On 64bit Linux this specific line of code isn't an issue since both
ptrdiff_t
andint64_t
are aliased tolong
-- but there it is impossible to create alibdivide::divider<long long>
object instead for the very same reasons.Similarly, on Windows x64 both
long
andint
are 32bit types, butlong long
is the corresponding 64bit type -- so eitherlibdivide::divider<long>
orlibdivide::divider<int>
will not work there, depending on which one is aliased toint32_t
.Is there a reason why the size-based dispatching introduced in the initial commit didn't work properly on AVR so that it had to be dropped for that?