Skip to content

Commit

Permalink
Merge pull request #13289 from drwells/fix-null-ptr-warning
Browse files Browse the repository at this point in the history
Fix a bogus warning about a null pointer in a lambda.
  • Loading branch information
bangerth committed Jan 25, 2022
2 parents c633c6c + 2418d18 commit 7614201
Showing 1 changed file with 16 additions and 13 deletions.
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

0 comments on commit 7614201

Please sign in to comment.