Redefinition of 'operator*' and 'operator/' errors
chillywillysoft opened this issue · 8 comments
I'm on a Mac using Xcode 11.7. In the build settings I have set Apple Clang C++ Language to C++17. I also tried GNU++17. I'm using the single header installation and have this issue with both a custom single file and the pre-built single file.
The errors I'm getting are Redefinition of 'operator*'
and Redefinition of 'operator/'
. It is happening on the four operators in struct ForbidsComposingWith
. It actually happens twice on the first of the four operators for a total of five errors.
I don't know if I've done something wrong or if this is a compatibility issue.
Sorry to hear you're having this problem! We haven't seen it before, and I don't have a good way of reproducing Apple errors.
Does this happen with any particular user code? Or is simply including the file enough?
And can you please post the full compiler errors? (Maybe attach it as a file and post a relevant snippet in a comment.)
Thank you for the quick response! This library looks really cool.
Simply including the file causes four errors (one on each of the operators). The additional error on the first operator does not reproduce reliably (Xcode is weird).
Here is the full compiler errors from simply including the file:
/path/au.hh:4362:27: Redefinition of 'operator/'
/path/main.mm:70:10: In file included from /path/main.mm:70:
/path/Garage/Car.hpp:14:10: In file included from /path/Garage/Car.hpp:14:
/path/au.hh:4362:27: Previous definition is here
/path/au.hh:4366:27: Redefinition of 'operator*'
/path/main.mm:70:10: In file included from /path/main.mm:70:
/path/Garage/Car.hpp:14:10: In file included from /path/Garage/Car.hpp:14:
/path/au.hh:4366:27: Previous definition is here
/path/au.hh:4370:27: Redefinition of 'operator/'
/path/main.mm:70:10: In file included from /path/main.mm:70:
/path/Garage/Car.hpp:14:10: In file included from /path/Garage/Car.hpp:14:
/path/au.hh:4370:27: Previous definition is here
/path/au.hh:4358:27: Redefinition of 'operator*'
/path/main.mm:70:10: In file included from /path/main.mm:70:
/path/Garage/Car.hpp:14:10: In file included from /path/Garage/Car.hpp:14:
/path/au.hh:5266:19: In instantiation of template class 'au::detail::ForbidsComposingWith<Constant, au::UnitProduct<>, QuantityPoint>' requested here
/path/au.hh:5329:47: In instantiation of template class 'au::Constant<au::UnitProduct<> >' requested here
/path/au.hh:5748:28: In instantiation of function template specialization 'au::make_constant<au::UnitProduct<> >' requested here
/path/au.hh:4358:27: Previous definition is here
I played with the compilers on godbolt until I found one that actually worked to reproduce the issue!
https://godbolt.org/z/jbP7z4oTM
I still can't iterate locally, but at least this gets me a foot in the door. 😄
By the way, it looks like this happens on Apple Clang 9 (I assume "armv7-a clang" means "Apple Clang"), but not on version 10 or later.
Great! Let me know if you want me to try compiling any iterations on my setup.
No need: here's a directly-iterable version:
https://godbolt.org/z/cvaY6vcEv
I'm about 80% sure it's a compiler bug.
- The "previous definition" comes from the exact same line, instantiated with (AFAICT) the exact same template parameters.
- This doesn't happen in other compilers.
- This doesn't happen in future versions of the same compiler.
Regardless, I think we might be able to make this work! I think the ForbidsComposingWith
is adding only very marginal value. I've put up a PR, #227. Could you please check whether it fixes your issue?
It compiles now.
Thank you! I really appreciate you taking part of your Saturday to help me.
I appreciate you trying the library! I hope it serves you well.