-
Notifications
You must be signed in to change notification settings - Fork 128
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
bindings: Help C++11 clients avoid calling serial constructor with MPI_Comm #2434
bindings: Help C++11 clients avoid calling serial constructor with MPI_Comm #2434
Conversation
…I_Comm Client code that does not enable `ADIOS2_USE_MPI` may accidentally try to pass a `MPI_Comm` instance to our constructor. If the type the MPI library uses to implement MPI_Comm happens to be convertible to one of the types offered by our serial constructors (e.g. `bool`), the invocation will appear to succeed but will ignore the communicator passed. Add explicitly deleted constructors that have better conversions for common `MPI_Comm` types. With this, an attempt in client code to call the `adios2::ADIOS` constructor with a `MPI_Comm` object will fail to compile with an error such as: error: use of deleted function 'adios2::ADIOS::ADIOS(void*)' adios2::ADIOS adios(comm); ...note: declared here ADIOS(void *define_ADIOS2_USE_MPI_to_use_MPI_constructor) = delete; ^~~~~
For reference, this came up in #2420 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support this; it's very helpful to have to avoid user errors I think. Can you also add it to the open
call in bindings/CXX11/adios2/cxx11/IO.h
thugh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bradking would a explicit
constructor be more effective than deleting implicit constructors?
It's not needed for |
No. An explicit constructor only prevents implicit calls to that constructor. In this case the call sites are already calling the constructor explicitly. The undesired conversion is taking place in the overload selection of that explicit call. |
@bradking I see, makes sense. Thanks for the explanation. A minor thing, should this be put in the |
Just pickin' your brains @bradking and @chuckatkins , is non-target legacy CMake going to have its Python 2 moment? |
The |
Client code that does not enable
ADIOS2_USE_MPI
may accidentally try to pass aMPI_Comm
instance to our constructor. If the type the MPI library uses to implement MPI_Comm happens to be convertible to one of the types offered by our serial constructors (e.g.bool
), the invocation will appear to succeed but will ignore the communicator passed. Add explicitly deleted constructors that have better conversions for commonMPI_Comm
types.With this, an attempt in client code to call the
adios2::ADIOS
constructor with aMPI_Comm
object will fail to compile with an error such as: