Commit fe755b00 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Added missing specialization to fix assertions with smart pointers

parent 66d4119e
Loading
Loading
Loading
Loading
+24 −16
Original line number Diff line number Diff line
@@ -143,21 +143,27 @@ fatalFailure()
}

template< typename T >
std::string
struct Formatter
{
   static std::string
   printToString( const T& value )
   {
      ::std::stringstream ss;
      ss << value;
      return ss.str();
   }
};

template<>
inline std::string
struct Formatter< bool >
{
   static std::string
   printToString( const bool& value )
   {
      if( value ) return "true";
      else return "false";
   }
};

template< typename T1, typename T2 >
__cuda_callable__ void
@@ -178,21 +184,23 @@ cmpHelperOpFailure( const char* assertion,
   printDiagnosticsCuda( assertion, message, file, function, line,
                         "Not supported in CUDA kernels." );
#else
   const std::string formatted_lhs_value = Formatter< T1 >::printToString( lhs_value );
   const std::string formatted_rhs_value = Formatter< T2 >::printToString( rhs_value );
   std::stringstream str;
   if( std::string(op) == "==" ) {
      str << "      Expected: " << lhs_expression;
      if( printToString(lhs_value) != lhs_expression ) {
         str << "\n      Which is: " << lhs_value;
      if( formatted_lhs_value != lhs_expression ) {
         str << "\n      Which is: " << formatted_lhs_value;
      }
      str << "\nTo be equal to: " << rhs_expression;
      if( printToString(rhs_value) != rhs_expression ) {
         str << "\n      Which is: " << rhs_value;
      if( formatted_rhs_value != rhs_expression ) {
         str << "\n      Which is: " << formatted_rhs_value;
      }
      str << std::endl;
   }
   else {
      str << "Expected: (" << lhs_expression << ") " << op << " (" << rhs_expression << "), "
          << "actual: " << lhs_value << " vs " << rhs_value << std::endl;
          << "actual: " << formatted_lhs_value << " vs " << formatted_rhs_value << std::endl;
   }
   printDiagnosticsHost( assertion, message, file, function, line,
                         str.str().c_str() );
+20 −0
Original line number Diff line number Diff line
@@ -472,4 +472,24 @@ class DevicePointer< Object, Devices::Cuda > : public SmartPointer
      Object* cuda_pointer;
};


#ifndef NDEBUG
namespace Assert {

template< typename Object, typename Device >
struct Formatter< DevicePointer< Object, Device > >
{
   static std::string
   printToString( const DevicePointer< Object, Device >& value )
   {
      ::std::stringstream ss;
      ss << "(DevicePointer< " << Object::getType() << ", " << Device::getDeviceType()
         << " > object at " << &value << ")";
      return ss.str();
   }
};

} // namespace Assert
#endif

} // namespace TNL
+20 −0
Original line number Diff line number Diff line
@@ -612,4 +612,24 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
      Object* cuda_pointer;
};


#ifndef NDEBUG
namespace Assert {

template< typename Object, typename Device >
struct Formatter< SharedPointer< Object, Device > >
{
   static std::string
   printToString( const SharedPointer< Object, Device >& value )
   {
      ::std::stringstream ss;
      ss << "(SharedPointer< " << Object::getType() << ", " << Device::getDeviceType()
         << " > object at " << &value << ")";
      return ss.str();
   }
};

} // namespace Assert
#endif

} // namespace TNL
+20 −0
Original line number Diff line number Diff line
@@ -292,5 +292,25 @@ class UniquePointer< Object, Devices::Cuda > : public SmartPointer
      Object* cuda_pointer;
};


#ifndef NDEBUG
namespace Assert {

template< typename Object, typename Device >
struct Formatter< UniquePointer< Object, Device > >
{
   static std::string
   printToString( const UniquePointer< Object, Device >& value )
   {
      ::std::stringstream ss;
      ss << "(UniquePointer< " << Object::getType() << ", " << Device::getDeviceType()
         << " > object at " << &value << ")";
      return ss.str();
   }
};

} // namespace Assert
#endif

} // namespace TNL