Skip to content
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

Fix a bogus warning about a null pointer in a lambda. #13289

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions source/base/mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,22 @@ namespace Utilities
// object, and as second argument a pointer-to-function, for which
// we here use a lambda function without captures that acts as the
// 'deleter' object: it calls `MPI_Type_free` and then deletes the
// pointer.
return {// The copy of the object:
new MPI_Datatype(result),
// The deleter:
[](MPI_Datatype *p) {
if (p != nullptr)
{
const int ierr = MPI_Type_free(p);
AssertThrowMPI(ierr);

delete p;
}
}};
// pointer. To avoid a compiler warning about a null this pointer
// in the lambda (which don't make sense: the lambda doesn't store
// anything), we create the deleter first.
auto deleter = [](MPI_Datatype *p) {
if (p != nullptr)
{
const int ierr = MPI_Type_free(p);
(void)ierr;
AssertNothrow(ierr == MPI_SUCCESS, ExcMPI(ierr));

delete p;
}
};

return std::unique_ptr<MPI_Datatype, void (*)(MPI_Datatype *)>(
new MPI_Datatype(result), deleter);
}


Expand Down