From d243c63741654864b4da9732f46f294668eb2b93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkovsky@mmg.fjfi.cvut.cz>
Date: Mon, 27 Dec 2021 13:20:39 +0100
Subject: [PATCH] clang-tidy: use nullptr [modernize-use-nullptr]

See https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
---
 src/TNL/Algorithms/detail/Reduction.hpp        |  6 +++---
 src/TNL/Config/parseCommandLine.h              |  2 +-
 src/TNL/Functions/TestFunction_impl.h          |  2 +-
 src/TNL/Images/DicomSeries_impl.h              | 18 +++++++++---------
 src/TNL/Images/PNGImage_impl.h                 | 12 ++++++------
 .../SubdomainOverlapsGetter.hpp                |  6 +++---
 src/TNL/SystemInfo.h                           |  2 +-
 src/TNL/TypeInfo.h                             |  4 ++--
 src/TNL/TypeTraits.h                           |  8 ++++----
 9 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/src/TNL/Algorithms/detail/Reduction.hpp b/src/TNL/Algorithms/detail/Reduction.hpp
index 1c0510dbe4..dc7d59f4a1 100644
--- a/src/TNL/Algorithms/detail/Reduction.hpp
+++ b/src/TNL/Algorithms/detail/Reduction.hpp
@@ -290,7 +290,7 @@ Reduction< Devices::Cuda >::reduce( const Index begin, const Index end, Fetch&&
    detail::CudaReductionKernelLauncher< Index, Result > reductionLauncher( begin, end );
 
    // start the reduce on the GPU
-   Result* deviceAux1( 0 );
+   Result* deviceAux1 = nullptr;
    const int reducedSize = reductionLauncher.start( reduce, fetch, identity, deviceAux1 );
 
 #ifdef CUDA_REDUCTION_PROFILING
@@ -379,8 +379,8 @@ Reduction< Devices::Cuda >::reduceWithArgument( const Index begin,
    detail::CudaReductionKernelLauncher< Index, Result > reductionLauncher( begin, end );
 
    // start the reduce on the GPU
-   Result* deviceAux1( nullptr );
-   Index* deviceIndexes( nullptr );
+   Result* deviceAux1 = nullptr;
+   Index* deviceIndexes = nullptr;
    const int reducedSize = reductionLauncher.startWithArgument( reduce, fetch, identity, deviceAux1, deviceIndexes );
 
 #ifdef CUDA_REDUCTION_PROFILING
diff --git a/src/TNL/Config/parseCommandLine.h b/src/TNL/Config/parseCommandLine.h
index 0603f10ec4..a26d23cdb1 100644
--- a/src/TNL/Config/parseCommandLine.h
+++ b/src/TNL/Config/parseCommandLine.h
@@ -247,7 +247,7 @@ parseCommandLine( int argc,
          }
          const std::string option = _option.substr( 2 );
          const ConfigEntryBase* entryBase = config_description.getEntry( option );
-         if( entryBase == NULL )
+         if( entryBase == nullptr )
             throw Exceptions::ConfigError( "Unknown parameter " + _option + "." );
          const String entryType = entryBase->getUIEntryType();
          if( i == argc - 1 )
diff --git a/src/TNL/Functions/TestFunction_impl.h b/src/TNL/Functions/TestFunction_impl.h
index 4efe45a2ae..c646c8a653 100644
--- a/src/TNL/Functions/TestFunction_impl.h
+++ b/src/TNL/Functions/TestFunction_impl.h
@@ -45,7 +45,7 @@ namespace Functions {
 
 template< int FunctionDimension, typename Real, typename Device >
 TestFunction< FunctionDimension, Real, Device >::TestFunction()
-: function( 0 ), operator_( 0 ), timeDependence( none ), timeScale( 1.0 )
+: function( nullptr ), operator_( nullptr ), timeDependence( none ), timeScale( 1.0 )
 {}
 
 template< int FunctionDimension, typename Real, typename Device >
diff --git a/src/TNL/Images/DicomSeries_impl.h b/src/TNL/Images/DicomSeries_impl.h
index 82d7c55ddb..91a0a2f0f7 100644
--- a/src/TNL/Images/DicomSeries_impl.h
+++ b/src/TNL/Images/DicomSeries_impl.h
@@ -38,8 +38,8 @@ filter( const struct dirent* dire )
 inline DicomSeries::DicomSeries( const String& filePath )
 {
 #ifdef HAVE_DCMTK_H
-   dicomImage = 0;
-   pixelData = 0;
+   dicomImage = nullptr;
+   pixelData = nullptr;
 #endif
    imagesInfo.imagesCount = 0;
    imagesInfo.maxColorValue = 0;
@@ -57,7 +57,7 @@ inline DicomSeries::~DicomSeries()
    for( int i = 0; i < length; i++ ) {
       DicomHeader* header = dicomSeriesHeaders[ i ];
       delete header;
-      header = 0;
+      header = nullptr;
    }
 
 #ifdef HAVE_DCMTK_H
@@ -178,7 +178,7 @@ DicomSeries::loadImage( const String& filePath, int number )
    // load image
    if( dicomImage )
       delete dicomImage;
-   dicomImage = NULL;
+   dicomImage = nullptr;
 
    dicomImage = new DicomImage( filePath.getString() );
 
@@ -192,7 +192,7 @@ DicomSeries::loadImage( const String& filePath, int number )
       return false;
    }
 
-   if( dicomImage != NULL ) {
+   if( dicomImage != nullptr ) {
       EI_Status imageStatus = dicomImage->getStatus();
       if( imageStatus == EIS_Normal ) {
          // ok - image loaded
@@ -203,12 +203,12 @@ DicomSeries::loadImage( const String& filePath, int number )
                    << std::endl;
 
          delete dicomImage;
-         dicomImage = NULL;
+         dicomImage = nullptr;
          return false;
       }
       else {
          delete dicomImage;
-         dicomImage = NULL;
+         dicomImage = nullptr;
          std::cerr << "Error: cannot load DICOM image (" << DicomImage::getString( dicomImage->getStatus() ) << ")"
                    << std::endl;
          return false;
@@ -276,7 +276,7 @@ DicomSeries::loadImage( const String& filePath, int number )
 
    // delete image object - data are stored separately
    delete dicomImage;
-   dicomImage = NULL;
+   dicomImage = nullptr;
    return true;
 #else
    std::cerr << "DICOM format is not supported in this build of TNL." << std::endl;
@@ -356,7 +356,7 @@ DicomSeries::freeData()
 #ifdef HAVE_DCMTK_H
    if( pixelData )
       delete pixelData;
-   pixelData = NULL;
+   pixelData = nullptr;
 #endif
 }
 
diff --git a/src/TNL/Images/PNGImage_impl.h b/src/TNL/Images/PNGImage_impl.h
index 8e812a1c26..3b946ff827 100644
--- a/src/TNL/Images/PNGImage_impl.h
+++ b/src/TNL/Images/PNGImage_impl.h
@@ -36,19 +36,19 @@ PNGImage< Index >::readHeader()
    /****
     * Allocate necessary memory
     */
-   this->png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
+   this->png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr );
    if( ! this->png_ptr )
       return false;
 
    this->info_ptr = png_create_info_struct( this->png_ptr );
    if( ! this->info_ptr ) {
-      png_destroy_read_struct( &this->png_ptr, (png_infopp) NULL, (png_infopp) NULL );
+      png_destroy_read_struct( &this->png_ptr, nullptr, nullptr );
       return false;
    }
 
    this->end_info = png_create_info_struct( this->png_ptr );
    if( ! this->end_info ) {
-      png_destroy_read_struct( &this->png_ptr, &this->info_ptr, (png_infopp) NULL );
+      png_destroy_read_struct( &this->png_ptr, &this->info_ptr, nullptr );
       return false;
    }
 
@@ -65,7 +65,7 @@ PNGImage< Index >::readHeader()
    /****
     * Read the header
     */
-   png_read_png( this->png_ptr, this->info_ptr, PNG_TRANSFORM_IDENTITY, NULL );
+   png_read_png( this->png_ptr, this->info_ptr, PNG_TRANSFORM_IDENTITY, nullptr );
    this->height = (Index) png_get_image_height( this->png_ptr, this->info_ptr );
    this->width = (Index) png_get_image_width( this->png_ptr, this->info_ptr );
    this->bit_depth = png_get_bit_depth( this->png_ptr, this->info_ptr );
@@ -184,13 +184,13 @@ bool
 PNGImage< Index >::writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid )
 {
 #ifdef HAVE_PNG_H
-   this->png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
+   this->png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr );
    if( ! png_ptr )
       return false;
 
    this->info_ptr = png_create_info_struct( this->png_ptr );
    if( ! this->info_ptr ) {
-      png_destroy_write_struct( &this->png_ptr, NULL );
+      png_destroy_write_struct( &this->png_ptr, nullptr );
       return false;
    }
 
diff --git a/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp b/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp
index 5a831cb783..579ca421af 100644
--- a/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp
+++ b/src/TNL/Meshes/DistributedMeshes/SubdomainOverlapsGetter.hpp
@@ -72,7 +72,7 @@ SubdomainOverlapsGetter< Grid< 1, Real, Device, Index > >::getOverlaps(
 
    if( MPI::GetSize() == 1 )
       return;
-   TNL_ASSERT_TRUE( distributedMesh != NULL, "" );
+   TNL_ASSERT_TRUE( distributedMesh != nullptr, "" );
 
    const CoordinatesType& subdomainCoordinates = distributedMesh->getSubdomainCoordinates();
    int rank = MPI::GetRank();
@@ -103,7 +103,7 @@ SubdomainOverlapsGetter< Grid< 2, Real, Device, Index > >::getOverlaps(
 
    if( MPI::GetSize() == 1 )
       return;
-   TNL_ASSERT_TRUE( distributedMesh != NULL, "" );
+   TNL_ASSERT_TRUE( distributedMesh != nullptr, "" );
 
    const CoordinatesType& subdomainCoordinates = distributedMesh->getSubdomainCoordinates();
    int rank = MPI::GetRank();
@@ -146,7 +146,7 @@ SubdomainOverlapsGetter< Grid< 3, Real, Device, Index > >::getOverlaps(
 
    if( MPI::GetSize() == 1 )
       return;
-   TNL_ASSERT_TRUE( distributedMesh != NULL, "" );
+   TNL_ASSERT_TRUE( distributedMesh != nullptr, "" );
 
    const CoordinatesType& subdomainCoordinates = distributedMesh->getSubdomainCoordinates();
    int rank = MPI::GetRank();
diff --git a/src/TNL/SystemInfo.h b/src/TNL/SystemInfo.h
index ba6069d281..a8e2daede0 100644
--- a/src/TNL/SystemInfo.h
+++ b/src/TNL/SystemInfo.h
@@ -70,7 +70,7 @@ protected:
       std::ifstream file( fileName.getString() );
       if( ! file ) {
          std::cerr << "Unable to read information from " << fileName << "." << std::endl;
-         return 0;
+         return 0;  // NOLINT(modernize-use-nullptr)
       }
       ResultType result;
       file >> result;
diff --git a/src/TNL/TypeInfo.h b/src/TNL/TypeInfo.h
index 070f353d26..3f1d3a8e88 100644
--- a/src/TNL/TypeInfo.h
+++ b/src/TNL/TypeInfo.h
@@ -33,7 +33,7 @@ demangle( const char* name )
 #if defined( TNL_HAS_CXXABI_H )
    int status = 0;
    std::size_t size = 0;
-   std::unique_ptr< char[], void ( * )( void* ) > result( abi::__cxa_demangle( name, NULL, &size, &status ), std::free );
+   std::unique_ptr< char[], void ( * )( void* ) > result( abi::__cxa_demangle( name, nullptr, &size, &status ), std::free );
    if( result.get() )
       return result.get();
 #endif
@@ -56,7 +56,7 @@ private:
    static constexpr std::false_type
    check( ... );
 
-   using type = decltype( check< std::decay_t< T > >( 0 ) );
+   using type = decltype( check< std::decay_t< T > >( nullptr ) );
 
 public:
    static constexpr bool value = type::value;
diff --git a/src/TNL/TypeTraits.h b/src/TNL/TypeTraits.h
index 4d3972af27..962546fe62 100644
--- a/src/TNL/TypeTraits.h
+++ b/src/TNL/TypeTraits.h
@@ -33,7 +33,7 @@ private:
    template< typename C > static NoType& test(...);
 
 public:
-   static constexpr bool value = ( sizeof( test< std::decay_t<T> >(0) ) == sizeof( YesType ) );
+   static constexpr bool value = ( sizeof( test< std::decay_t< T > >( nullptr ) ) == sizeof( YesType ) );
 };
 
 /**
@@ -74,7 +74,7 @@ private:
    template< typename >
    static constexpr std::false_type check(...);
 
-   using type = decltype(check<std::decay_t<T> >(0));
+   using type = decltype( check< std::decay_t< T > >( nullptr ) );
 
 public:
    static constexpr bool value = type::value;
@@ -101,7 +101,7 @@ private:
    template< typename >
    static constexpr std::false_type check(...);
 
-   using type = decltype(check<std::decay_t<T> >(0));
+   using type = decltype( check< std::decay_t< T > >( nullptr ) );
 
 public:
    static constexpr bool value = type::value;
@@ -128,7 +128,7 @@ private:
    template< typename >
    static constexpr std::false_type check(...);
 
-   using type = decltype(check<std::decay_t<T> >(0));
+   using type = decltype( check< std::decay_t< T > >( nullptr ) );
 
 public:
    static constexpr bool value = type::value;
-- 
GitLab