gcc 9.3 claims operator++ is ambiguous
usefulcat opened this issue · 1 comments
I added the following test case to tests.cpp, which is just a trivial combination of the contents of the PreIncrementable and PostIncrementable tests:
TEST_CASE("PreAndPostIncrementable")
{
using StrongInt = fluent::NamedType<int, struct StrongIntTag, fluent::PreIncrementable, fluent::PostIncrementable>;
{
StrongInt a{1};
StrongInt b = ++a;
CHECK( a.get() == 2 );
CHECK( b.get() == 2 );
}
{
StrongInt a{1};
StrongInt b = a++;
CHECK( a.get() == 2 );
CHECK( b.get() == 1 );
}
}
gcc 9.3 fails to compile it, saying "error: request for member ‘operator++’ is ambiguous".
I thought I would try fixing it myself but so far I haven't been able to figure out why it doesn't work, let alone how to fix it. This problem also affects any type that uses Arithmetic, which is how I originally discovered it.
Ran into the same problem. I think this is a bug in gcc. I just opened a question stackoverflow regarding this: https://stackoverflow.com/questions/69540048/gcc-ambiguous-inherited-increment
I don't think that the hot-fix (using
the operators) will work in general for NamedType, since it would have to know if it is pre- and postincrementable. But adding the following lines to struct Arithmetic
fixes it for arithmetic types at least:
using PostIncrementable<T>::operator++;
using PreIncrementable<T>::operator++;
using PostDecrementable<T>::operator--;
using PreDecrementable<T>::operator--;
I will add a pull request for this.