diff --git a/cpp/scope_timer.hpp b/cpp/scope_timer.hpp
index 98c23c8019d7003f2c123cab3cdeaefad793f25c..82673ed35865714d2777673268c96e9596e4165b 100644
--- a/cpp/scope_timer.hpp
+++ b/cpp/scope_timer.hpp
@@ -374,7 +374,7 @@ public:
 
         if(myrank != 0){
             const std::string strOutput = myResults.str();
-            assert(strOutput.length() <= std::numeric_limits<int>::max());
+            assert(strOutput.length() <= std::numeric_limits<decltype(strOutput.length())>::max());
             int sizeOutput = int(strOutput.length());
             retMpi = MPI_Send(&sizeOutput, 1, MPI_INT, 0, 99, inComm);
             assert(retMpi == MPI_SUCCESS);
@@ -639,7 +639,7 @@ public:
 
             if(myRank != 0){
                 const std::string strOutput = myResults.str();
-                assert(strOutput.length() <= std::numeric_limits<int>::max());
+                assert(strOutput.length() <= std::numeric_limits<decltype(strOutput.length())>::max());
                 int sizeOutput = int(strOutput.length());
                 retMpi = MPI_Send(&sizeOutput, 1, MPI_INT, 0, 99, inComm);
                 assert(retMpi == MPI_SUCCESS);