-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
CubicalComplex operators not found when same operators are already defined in DGtal namespace. #1362
Comments
I am a bit surprised that the compiler does not do a correct name lookup for operator-. As I see in CubicalComplex.h and CubicalComplexFunctions.h, operator- expect CubicalComplex<T1,T2>. |
Yes, from what I've read, I think that's because the operators are in a sub-namespace and since the compiler already founds corresponding functions in DGtal namespace using "argument-dependent lookup", it doesn't look further... |
Your fix seems correct for CubicalComplex.ih |
Ok, we should include |
Perhaps include it in CubicalComplex.h instead to expose the fact that they come together. |
By the way, should we put DGtal::operator+( PointVector... ) and others in DGtal::functions ? |
We will then have the same issue: if a non-related |
So we should put operator+( CubicalComplex< >... ) in DGtal namespace (and not DGtal::functions) and include CubicalComplexFunctions in CubicalComplex.h |
ping @rolanddenis |
Yep, I agree ! |
Fixed in #1390, thanks! |
When including a header that defines the
operator-
as non-member function in theDGtal
namespace, the sameoperator-
that applies onCubicalComplex
and that is defined in theDGtal::functions
namespace is not found by the Clang compiler (no problem with GNU compiler) when compilingtestCubicalComplex.cpp
.This compilation error arises in
CubicalComplex.ih
:when compiling PR #1345 due to the declaration of
PointVector
operators in theDGtal
namespace. It can also be reproduced by including the (unnecessary) headerDGtal/dec/KForm.h
at the beginning oftestCubicalComplex.cpp
(it also defines anoperator-
in theDGtal
namespace).It seems to come from the name lookup rules that are not completely clear for me. It seems that during the argument-dependent lookup step (see https://en.cppreference.com/w/cpp/language/adl), if a function with same name is found (argument type doesn't matter at this step) in the namespace that contains the arguments of the operator (aka
DGtal
), then the lookup stage is (partly) aborted and using directive (using namespace ...
) are ignored.So, when no
operator-
is found inDGtal
namespace, then the using directive is considered and theDGtal::functions::operator-
is found. But if anoperator-
is found inDGtal
namespace (like with thePointVector
related PR or when includingDGtal/dec/KForm.h
), then theDGtal::functions
namespace is ignored and the overload resolution fails since the found function cannot takeCubicalComplex
as parameters.I don't know if the compiler should be able to found the right operators because of the friend declarations in
CubicalComplex
... (is this a bug of Clang ?)An easy fix (but only for this specific lines of code) is to replace the using directive by the using declaration:
that would bring the right
operator-
at the block scope (instead of the namespace scope) and that would then be considered during the unqualified name lookup stage.Otherwise, it seems to be recommended to put operators in the same namespace as its arguments but it may implies many modifications.
Another solution would be to add using declarations for each operator after their forward declarations in
CubicalComplex.h
, like:Apart of this, there is several dependency issues in
CubicalComplex.h
andCubicalComplexFunctions.h
:operator-
defined inCubicalComplexFunction.h
is needed inCubicalComplex.ih
but includingCubicalComplex.h
alone doesn't lead to includeCubicalComplexFunction.h
CubicalComplex.h
andCubicalComplexFunction.h
alone doesn't compile sinceCubicalComplexFunction.ih
useSpaceND
andHyperRectDomain
that are not included.The text was updated successfully, but these errors were encountered: