From: Daniel Arndt Date: Mon, 14 Jan 2019 14:57:02 +0000 (+0100) Subject: Use modernize-use-nullptr X-Git-Tag: v9.1.0-rc1~439^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7033442f2afc4fddab8d6f514f8eaf050bf2f406;p=dealii.git Use modernize-use-nullptr --- diff --git a/contrib/utilities/run_clang_tidy.sh b/contrib/utilities/run_clang_tidy.sh index ebf6f8e5f2..4cfeb0c5cd 100755 --- a/contrib/utilities/run_clang_tidy.sh +++ b/contrib/utilities/run_clang_tidy.sh @@ -49,8 +49,9 @@ ARGS="-D DEAL_II_WITH_MUPARSER=OFF -D DEAL_II_WITH_MPI=ON -D CMAKE_EXPORT_COMPIL CHECKS="-*, cppcoreguidelines-pro-type-static-cast-downcast, google-readability-casting, - modernize-use-emplace, modernize-deprecated-headers, + modernize-use-emplace, + modernize-use-nullptr, modernize-use-using, mpi-*, performance-*, diff --git a/include/deal.II/base/hdf5.h b/include/deal.II/base/hdf5.h index a036daa425..292640535d 100644 --- a/include/deal.II/base/hdf5.h +++ b/include/deal.II/base/hdf5.h @@ -478,7 +478,7 @@ namespace HDF5 * * When reading a hyperslab, HDF5 also allows to provide "stride" and * "block" parameters (see the [HDF5 documentation](https://support.hdfgroup.org/HDF5/doc1.8/RM/RM_H5S.html#Dataspace-SelectHyperslab)). - * These are not used by the current function and set to `NULL`. However + * These are not used by the current function and set to `nullptr`. However * these parameters can be used with the function * read_hyperslab(const std::vector &, const std::vector &, const std::vector &, const std::vector &, const std::vector &) * @@ -628,7 +628,7 @@ namespace HDF5 * * When writing a hyperslab, HDF5 also allows to provide "stride" and * "block" parameters (see the [HDF5 documentation](https://support.hdfgroup.org/HDF5/doc1.8/RM/RM_H5S.html#Dataspace-SelectHyperslab)). - * These are not used by the current function and set to `NULL`. However + * These are not used by the current function and set to `nullptr`. However * these parameters can be used with the function * write_hyperslab(const Container &data, const std::vector &data_dimensions, const std::vector &offset, const std::vector &stride, const std::vector &count, const std::vector &block). * diff --git a/include/deal.II/fe/fe_tools.templates.h b/include/deal.II/fe/fe_tools.templates.h index 36b5665eb1..7a0f374a30 100644 --- a/include/deal.II/fe/fe_tools.templates.h +++ b/include/deal.II/fe/fe_tools.templates.h @@ -210,7 +210,7 @@ namespace FETools // given FEs unsigned int n_shape_functions = 0; for (unsigned int i = 0; i < fes.size(); ++i) - if (multiplicities[i] > 0) // check needed as fe might be NULL + if (multiplicities[i] > 0) // check needed as fe might be nullptr n_shape_functions += fes[i]->dofs_per_cell * multiplicities[i]; // generate the array that will hold the output @@ -376,27 +376,27 @@ namespace FETools // given FEs unsigned int n_shape_functions = 0; for (unsigned int i = 0; i < fes.size(); ++i) - if (multiplicities[i] > 0) // needed because fe might be NULL + if (multiplicities[i] > 0) // needed because fe might be nullptr n_shape_functions += fes[i]->dofs_per_cell * multiplicities[i]; unsigned int n_components = 0; if (do_tensor_product) { for (unsigned int i = 0; i < fes.size(); ++i) - if (multiplicities[i] > 0) // needed because fe might be NULL + if (multiplicities[i] > 0) // needed because fe might be nullptr n_components += fes[i]->n_components() * multiplicities[i]; } else { for (unsigned int i = 0; i < fes.size(); ++i) - if (multiplicities[i] > 0) // needed because fe might be NULL + if (multiplicities[i] > 0) // needed because fe might be nullptr { n_components = fes[i]->n_components(); break; } // Now check that all FEs have the same number of components: for (unsigned int i = 0; i < fes.size(); ++i) - if (multiplicities[i] > 0) // needed because fe might be NULL + if (multiplicities[i] > 0) // needed because fe might be nullptr Assert(n_components == fes[i]->n_components(), ExcDimensionMismatch(n_components, fes[i]->n_components())); diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index f1b37b0c95..7315fd9908 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -3285,7 +3285,7 @@ inline unsigned int FEEvaluationBase:: get_mapping_data_index_offset() const { - if (matrix_info == 0) + if (matrix_info == nullptr) return 0; else { diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index 20148e4647..b4d3de0581 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -181,7 +181,7 @@ namespace Particles * point to the first entry of the array to which the data should be * written. This function is meant for serializing all particle properties * and later de-serializing the properties by calling the appropriate - * constructor Particle(void *&data, PropertyPool *property_pool = NULL); + * constructor Particle(void *&data, PropertyPool *property_pool = nullptr); * * @param [in,out] data The memory location to write particle data * into. This pointer points to the begin of the memory, in which the diff --git a/include/deal.II/particles/particle_accessor.h b/include/deal.II/particles/particle_accessor.h index 2d74711b07..d104f66d99 100644 --- a/include/deal.II/particles/particle_accessor.h +++ b/include/deal.II/particles/particle_accessor.h @@ -41,7 +41,7 @@ namespace Particles * point to the first element in which the data should be written. This * function is meant for serializing all particle properties and * afterwards de-serializing the properties by calling the appropriate - * constructor Particle(void *&data, PropertyPool *property_pool = NULL); + * constructor Particle(void *&data, PropertyPool *property_pool = nullptr); * * @param [in,out] data The memory location to write particle data * into. This pointer points to the begin of the memory, in which the diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 897131aeee..881f0e7878 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -4901,7 +4901,7 @@ namespace DataOutBase // later char *file_name = (char *)flags.tecplot_binary_file_name; - if (file_name == NULL) + if (file_name == nullptr) { // At least in debug mode we should tell users why they don't get // tecplot binary output @@ -5164,12 +5164,13 @@ namespace DataOutBase // As we don't do anything else with tec_var_names following const_cast is // ok char *var_names = const_cast(tec_var_names.c_str()); - ierr = TECINI(NULL, var_names, file_name, dot, &tec_debug, &is_double); + ierr = TECINI(nullptr, var_names, file_name, dot, &tec_debug, &is_double); Assert(ierr == 0, ExcErrorOpeningTecplotFile(file_name)); char FEBLOCK[] = {'F', 'E', 'B', 'L', 'O', 'C', 'K', 0}; - ierr = TECZNE(NULL, &num_nodes, &num_cells, &cell_type, FEBLOCK, NULL); + ierr = + TECZNE(nullptr, &num_nodes, &num_cells, &cell_type, FEBLOCK, nullptr); Assert(ierr == 0, ExcTecplotAPIError()); diff --git a/source/base/exceptions.cc b/source/base/exceptions.cc index 0d17ae45d2..08d6338253 100644 --- a/source/base/exceptions.cc +++ b/source/base/exceptions.cc @@ -120,7 +120,7 @@ ExceptionBase::ExceptionBase(const ExceptionBase &exc) ExceptionBase::~ExceptionBase() noexcept { - free(stacktrace); // free(NULL) is allowed + free(stacktrace); // free(nullptr) is allowed stacktrace = nullptr; } @@ -161,7 +161,7 @@ ExceptionBase::what() const noexcept // backtrace_symbols. // first delete old stacktrace if necessary - free(stacktrace); // free(NULL) is allowed + free(stacktrace); // free(nullptr) is allowed stacktrace = backtrace_symbols(raw_stacktrace, n_stacktrace_frames); #endif diff --git a/source/base/hdf5.cc b/source/base/hdf5.cc index b5ff668b92..bb51d880e3 100644 --- a/source/base/hdf5.cc +++ b/source/base/hdf5.cc @@ -619,7 +619,8 @@ namespace HDF5 Assert(rank_ret >= 0, ExcInternalError()); rank = rank_ret; dimensions.resize(rank); - rank_ret = H5Sget_simple_extent_dims(*dataspace, dimensions.data(), NULL); + rank_ret = + H5Sget_simple_extent_dims(*dataspace, dimensions.data(), nullptr); AssertDimension(rank_ret, static_cast(rank)); size = 1; @@ -655,7 +656,7 @@ namespace HDF5 delete pointer; }); - *dataspace = H5Screate_simple(rank, dimensions.data(), NULL); + *dataspace = H5Screate_simple(rank, dimensions.data(), nullptr); Assert(*dataspace >= 0, ExcMessage("Error at H5Screate_simple")); *hdf5_reference = H5Dcreate2(parent_group_id, @@ -729,7 +730,7 @@ namespace HDF5 Container data = internal::initialize_container(data_dimensions); - memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); + memory_dataspace = H5Screate_simple(1, data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); ret = H5Sselect_elements(*dataspace, H5S_SELECT_SET, @@ -781,10 +782,14 @@ namespace HDF5 Container data = internal::initialize_container(data_dimensions); memory_dataspace = - H5Screate_simple(data_dimensions.size(), data_dimensions.data(), NULL); + H5Screate_simple(data_dimensions.size(), data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); - ret = H5Sselect_hyperslab( - *dataspace, H5S_SELECT_SET, offset.data(), NULL, count.data(), NULL); + ret = H5Sselect_hyperslab(*dataspace, + H5S_SELECT_SET, + offset.data(), + nullptr, + count.data(), + nullptr); Assert(ret >= 0, ExcMessage("Error at H5Sselect_hyperslab")); internal::set_plist(plist, mpi); @@ -830,7 +835,7 @@ namespace HDF5 Container data = internal::initialize_container(data_dimensions); memory_dataspace = - H5Screate_simple(data_dimensions.size(), data_dimensions.data(), NULL); + H5Screate_simple(data_dimensions.size(), data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); ret = H5Sselect_hyperslab(*dataspace, H5S_SELECT_SET, @@ -877,18 +882,18 @@ namespace HDF5 hid_t plist; herr_t ret; - memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); + memory_dataspace = H5Screate_simple(1, data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); ret = H5Sselect_none(*dataspace); Assert(ret >= 0, ExcMessage("H5Sselect_none")); internal::set_plist(plist, mpi); - // The pointer of data can safely be NULL, see the discussion at the HDF5 + // The pointer of data can safely be nullptr, see the discussion at the HDF5 // forum: // https://forum.hdfgroup.org/t/parallel-i-o-does-not-support-filters-yet/884/17 ret = H5Dread( - *hdf5_reference, *t_type, memory_dataspace, *dataspace, plist, NULL); + *hdf5_reference, *t_type, memory_dataspace, *dataspace, plist, nullptr); Assert(ret >= 0, ExcMessage("Error at H5Dread")); internal::release_plist(plist, @@ -954,7 +959,7 @@ namespace HDF5 herr_t ret; - memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); + memory_dataspace = H5Screate_simple(1, data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); ret = H5Sselect_elements(*dataspace, H5S_SELECT_SET, @@ -1009,10 +1014,14 @@ namespace HDF5 herr_t ret; memory_dataspace = - H5Screate_simple(data_dimensions.size(), data_dimensions.data(), NULL); + H5Screate_simple(data_dimensions.size(), data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); - ret = H5Sselect_hyperslab( - *dataspace, H5S_SELECT_SET, offset.data(), NULL, count.data(), NULL); + ret = H5Sselect_hyperslab(*dataspace, + H5S_SELECT_SET, + offset.data(), + nullptr, + count.data(), + nullptr); Assert(ret >= 0, ExcMessage("Error at H5Sselect_hyperslab")); internal::set_plist(plist, mpi); @@ -1057,7 +1066,7 @@ namespace HDF5 herr_t ret; memory_dataspace = - H5Screate_simple(data_dimensions.size(), data_dimensions.data(), NULL); + H5Screate_simple(data_dimensions.size(), data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); ret = H5Sselect_hyperslab(*dataspace, H5S_SELECT_SET, @@ -1103,18 +1112,18 @@ namespace HDF5 hid_t plist; herr_t ret; - memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); + memory_dataspace = H5Screate_simple(1, data_dimensions.data(), nullptr); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); ret = H5Sselect_none(*dataspace); Assert(ret >= 0, ExcMessage("Error at H5PSselect_none")); internal::set_plist(plist, mpi); - // The pointer of data can safely be NULL, see the discussion at the HDF5 + // The pointer of data can safely be nullptr, see the discussion at the HDF5 // forum: // https://forum.hdfgroup.org/t/parallel-i-o-does-not-support-filters-yet/884/17 ret = H5Dwrite( - *hdf5_reference, *t_type, memory_dataspace, *dataspace, plist, NULL); + *hdf5_reference, *t_type, memory_dataspace, *dataspace, plist, nullptr); Assert(ret >= 0, ExcMessage("Error at H5Dwrite")); internal::release_plist(plist, diff --git a/source/base/multithread_info.cc b/source/base/multithread_info.cc index af64a8b7d8..0283ed8fdf 100644 --- a/source/base/multithread_info.cc +++ b/source/base/multithread_info.cc @@ -68,7 +68,7 @@ MultithreadInfo::get_n_cpus() mib[0] = CTL_HW; mib[1] = HW_NCPU; len = sizeof(n_cpus); - sysctl(mib, 2, &n_cpus, &len, NULL, 0); + sysctl(mib, 2, &n_cpus, &len, nullptr, 0); return n_cpus; } diff --git a/source/base/subscriptor.cc b/source/base/subscriptor.cc index eec6f7305b..886483bb34 100644 --- a/source/base/subscriptor.cc +++ b/source/base/subscriptor.cc @@ -164,7 +164,7 @@ Subscriptor::subscribe(std::atomic *const validity, object_info = &typeid(*this); ++counter; - const char *const name = (id != 0) ? id : unknown_subscriber; + const char *const name = (id != nullptr) ? id : unknown_subscriber; map_iterator it = counter_map.find(name); if (it == counter_map.end()) diff --git a/source/fe/fe_enriched.cc b/source/fe/fe_enriched.cc index fc0b24487b..195101e5ee 100644 --- a/source/fe/fe_enriched.cc +++ b/source/fe/fe_enriched.cc @@ -727,7 +727,8 @@ FE_Enriched::multiply_by_enrichment( continue; Assert(enrichments[base_no - 1][m](cell) != nullptr, - ExcMessage("The pointer to the enrichment function is NULL")); + ExcMessage( + "The pointer to the enrichment function is not set")); Assert(enrichments[base_no - 1][m](cell)->n_components == 1, ExcMessage( diff --git a/source/fe/fe_nedelec_sz.cc b/source/fe/fe_nedelec_sz.cc index 0afb57d153..9e3eebb637 100644 --- a/source/fe/fe_nedelec_sz.cc +++ b/source/fe/fe_nedelec_sz.cc @@ -1910,7 +1910,7 @@ FE_NedelecSZ::fill_fe_values( &data) const { // Convert to the correct internal data class for this FE class. - Assert(dynamic_cast(&fe_internal) != 0, + Assert(dynamic_cast(&fe_internal) != nullptr, ExcInternalError()); const InternalData &fe_data = static_cast(fe_internal); @@ -2034,7 +2034,7 @@ FE_NedelecSZ::fill_fe_face_values( // data for this class. fails with // an exception if that is not // possible - Assert(dynamic_cast(&fe_internal) != 0, + Assert(dynamic_cast(&fe_internal) != nullptr, ExcInternalError()); const InternalData &fe_data = static_cast(fe_internal); diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index 9ad476e4fd..ef82491831 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -321,7 +321,7 @@ namespace PETScWrappers // then restore the matrix and return the number of columns in this row as // queried previously. Starting with PETSc 3.4, MatRestoreRow actually - // resets the last three arguments to zero/NULL, to avoid abuse of pointers + // resets the last three arguments to nullptr, to avoid abuse of pointers // now dangling. as a consequence, we need to save the size of the array // and return the saved value. const PetscInt ncols_saved = ncols; diff --git a/source/lac/trilinos_vector.cc b/source/lac/trilinos_vector.cc index 0f53cca4bb..5adf4bb6e3 100644 --- a/source/lac/trilinos_vector.cc +++ b/source/lac/trilinos_vector.cc @@ -433,8 +433,9 @@ namespace TrilinosWrappers // somewhere. This can happen when a vector lives in GrowingVectorMemory // data structures. Thus, the following code is commented out. // - // if (my_comm != NULL && v_comm != NULL && my_comm->DataPtr() != - // v_comm->DataPtr()) + // if (my_comm != nullptr && + // v_comm != nullptr && + // my_comm->DataPtr() != v_comm->DataPtr()) // { // int communicators_same = 0; // const int ierr = MPI_Comm_compare (my_comm->GetMpiComm(),