I'm introducing move semantics in a C++ library.
There is some legacy client code that uses the library that breaks because some assumptions were made about the assignment operator that are invalid when assignment is really move assignment. This is a combination of a lack of clear documentation in the library and some questionable practices in the client code. Nevertheless, I'd like to find a way to easily find all places in the code where the move assignment operator for a template class is used.
I've figured out a way to do this by forcing a compiler error when the move assignment is invoked. With gcc, if this is a direct invocation, I get the line number in the source code of the invocation. Unfortunately, if it is an indirect invocation, I don't get the line number. I also tried clang, but no luck there either.
The issue is this. In the template class of interest, say template<class T> Foo { ... }, I can define the move assignment operator so that compilation fails when it is instantiated with any type T. This gives me the line number I want if client code invokes it directly. However, if there is a class X that has a member, say Foo<int>, and X gets an implicitly defined move assignment operator, then an invocation of this operator gets flagged as an error, but the only line number I get in gcc and clang is the line number of the definition of class X, which is not very helpful.
Does anybody know of any tools to help with this?
Thanks!
Aucun commentaire:
Enregistrer un commentaire