From: eap Date: Fri, 6 Dec 2019 12:43:49 +0000 (+0300) Subject: LOT4: fix -Wconversion in INTERP_KERNEL X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9da60cba1f4b9fd6f77535371a8e49b2ff4dbec4;p=tools%2Fmedcoupling.git LOT4: fix -Wconversion in INTERP_KERNEL --- diff --git a/src/INTERP_KERNEL/CMakeLists.txt b/src/INTERP_KERNEL/CMakeLists.txt index 4b70eceba..6cf3b22ba 100644 --- a/src/INTERP_KERNEL/CMakeLists.txt +++ b/src/INTERP_KERNEL/CMakeLists.txt @@ -72,6 +72,10 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/GaussPoints ) +IF (NOT DEFINED MSVC) + ADD_DEFINITIONS(-Wsign-compare -Wconversion) +ENDIF() + SET(PLATFORM_MMAP) IF(NOT WIN32) SET(PLATFORM_MMAP "-D_POSIX_MAPPED_FILES") diff --git a/src/INTERP_KERNEL/CellModel.cxx b/src/INTERP_KERNEL/CellModel.cxx index e79822e62..ff27642f0 100644 --- a/src/INTERP_KERNEL/CellModel.cxx +++ b/src/INTERP_KERNEL/CellModel.cxx @@ -456,14 +456,14 @@ namespace INTERP_KERNEL if(_dim==2) { if(_type==NORM_POLYGON) - return lgth; + return FromIdType(lgth); else - return lgth/2; + return FromIdType(lgth/2); } else if(_dim==1) - return lgth;//NORM_POLYL + return FromIdType(lgth);//NORM_POLYL else - return std::count(conn,conn+lgth,-1)+1; + return (unsigned)std::count(conn,conn+lgth,-1)+1; } unsigned CellModel::getNumberOfEdgesIn3D(const mcIdType *conn, mcIdType lgth) const @@ -471,7 +471,7 @@ namespace INTERP_KERNEL if(!isDynamic()) return _nb_of_little_sons; else//polyhedron - return (lgth-std::count(conn,conn+lgth,-1))/2; + return FromIdType(lgth-std::count(conn,conn+lgth,-1))/2; } /*! @@ -591,7 +591,7 @@ namespace INTERP_KERNEL } const mcIdType *where2=std::find(where,nodalConn+lgth,-1); std::copy(where,where2,sonNodalConn); - return where2-where; + return FromIdType(where2-where); } else throw INTERP_KERNEL::Exception("CellModel::fillSonCellNodalConnectivity2 : no sons on NORM_POLYL !"); @@ -753,7 +753,7 @@ namespace INTERP_KERNEL where++; } const mcIdType *where2=std::find(where,nodalConn+lgth,-1); - return where2-where; + return FromIdType(where2-where); } else throw INTERP_KERNEL::Exception("CellModel::getNumberOfNodesConstituentTheSon2 : no sons on NORM_POLYL !"); @@ -805,7 +805,7 @@ namespace INTERP_KERNEL } else { - int p=(lgth+1)/2; + mcIdType p=(lgth+1)/2; std::vector tmp(2*p); std::vector::iterator it=std::copy(conn1,conn1+p,tmp.begin()); std::copy(conn1,conn1+p,it); diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx index d040be703..794c664db 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelAsmX86.cxx @@ -45,7 +45,7 @@ std::vector INTERP_KERNEL::AsmX86::convertIntoMachineLangage(const std::ve char *INTERP_KERNEL::AsmX86::copyToExecMemZone(const std::vector& ml, unsigned& offset) const { char *ret=0; - int lgth=ml.size(); + std::size_t lgth=ml.size(); #ifdef _POSIX_MAPPED_FILES # ifdef __APPLE__ ret=(char *)mmap(0,lgth,PROT_EXEC | PROT_WRITE,MAP_ANON | MAP_PRIVATE,-1,0); @@ -492,7 +492,7 @@ void INTERP_KERNEL::AsmX86::appendAddress(const std::string& addr, int nbOfByte, for(int k=0;k>=8; } diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx index ab5e989d9..ab5a4a79b 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx @@ -233,7 +233,8 @@ void DecompositionInUnitBase::tryToConvertInUnit(double val) DecompositionInUnitBase &DecompositionInUnitBase::operator*(const DecompositionInUnitBase& other) { - _value[0]+=other._value[0]; _value[1]+=other._value[1]; _value[2]+=other._value[2]; _value[3]+=other._value[3]; _value[4]+=other._value[4]; + // += causes ' conversion to 'short int' from 'int' may alter its value [-Wconversion]' + _value[0]=(short)(_value[0]+other._value[0]); _value[1]=(short)(_value[1]+other._value[1]); _value[2]=(short)(_value[2]+other._value[2]); _value[3]=(short)(_value[3]+other._value[3]); _value[4]=(short)(_value[4]+other._value[4]); _mult_fact_to_base*=other._mult_fact_to_base; _add_to_base=0.; return *this; @@ -241,7 +242,8 @@ DecompositionInUnitBase &DecompositionInUnitBase::operator*(const DecompositionI DecompositionInUnitBase &DecompositionInUnitBase::operator/(const DecompositionInUnitBase& other) { - _value[0]-=other._value[0]; _value[1]-=other._value[1]; _value[2]-=other._value[2]; _value[3]-=other._value[3]; _value[4]-=other._value[4]; + // -= causes ' conversion to 'short int' from 'int' may alter its value [-Wconversion]' + _value[0]=(short)(_value[0]-other._value[0]); _value[1]=(short)(_value[1]-other._value[1]); _value[2]=(short)(_value[2]-other._value[2]); _value[3]=(short)(_value[3]-other._value[3]); _value[4]=(short)(_value[4]-other._value[4]); _mult_fact_to_base/=other._mult_fact_to_base; _add_to_base=0.; return *this; @@ -252,7 +254,8 @@ DecompositionInUnitBase &DecompositionInUnitBase::operator^(const DecompositionI if(!other.isAdimensional()) throw INTERP_KERNEL::Exception("Trying to execute operator ^ with a second member not adimensionnal"); int exp=couldItBeConsideredAsInt(other._mult_fact_to_base); - _value[0]*=exp; _value[1]*=exp; _value[2]*=exp; _value[3]*=exp; _value[4]*=exp; + // *= causes ' conversion to 'short int' from 'int' may alter its value [-Wconversion]' + _value[0]=(short)(_value[0]*exp); _value[1]=(short)(_value[1]*exp); _value[2]=(short)(_value[2]*exp); _value[3]=(short)(_value[3]*exp); _value[4]=(short)(_value[4]*exp); _mult_fact_to_base=powInt(_mult_fact_to_base,exp); _add_to_base=0.; return *this; diff --git a/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx b/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx index 6b699a584..42adbc54c 100644 --- a/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx +++ b/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx @@ -172,7 +172,7 @@ int GaussInfo::getGaussCoordDim() const { if( _my_nb_gauss ) { - return _my_gauss_coord.size()/_my_nb_gauss; + return (int)_my_gauss_coord.size()/_my_nb_gauss; } else { @@ -187,7 +187,7 @@ int GaussInfo::getReferenceCoordDim() const { if( _my_nb_ref ) { - return _my_reference_coord.size()/_my_nb_ref; + return (int)(_my_reference_coord.size()/_my_nb_ref); } else { @@ -2967,7 +2967,7 @@ void GaussCoords::addGaussInfo( NormalizedCellType theGeometry, aReferenceCoord.push_back(theReferenceCoord[i]); - GaussInfo* info = new GaussInfo( theGeometry, aGaussCoord, theNbGauss, aReferenceCoord, theNbRef); + GaussInfo* info = new GaussInfo( theGeometry, aGaussCoord, FromIdType(theNbGauss), aReferenceCoord, FromIdType(theNbRef)); info->initLocalInfo(); //If info with cell type doesn't exist add it @@ -2979,7 +2979,7 @@ void GaussCoords::addGaussInfo( NormalizedCellType theGeometry, } else { - int index = std::distance(_my_gauss_info.begin(),it); + std::size_t index = std::distance(_my_gauss_info.begin(),it); delete (*it); _my_gauss_info[index] = info; } diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx index 735728239..a2f2fe97b 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx @@ -587,7 +587,7 @@ double ComposedEdge::isInOrOutAlg(Node *nodeToTest, const std::set& nodes std::vector radialDistrib3(radialDistrib.size()); std::transform(radialDistrib2.begin(),radialDistrib2.end(),radialDistrib.begin(),radialDistrib3.begin(),std::minus()); std::vector::iterator iter3=max_element(radialDistrib3.begin(),radialDistrib3.end()); - int i=iter3-radialDistrib3.begin(); + std::size_t i=iter3-radialDistrib3.begin(); // ok for e1 - Let's go. EdgeInfLin *e1=new EdgeInfLin(nodeToTest,radialDistrib[i]+radialDistrib3[i]/2.); double ref=e1->getCharactValue(*nodeToTest); diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DEdge.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DEdge.cxx index 7617feb11..a3220bf61 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DEdge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DEdge.cxx @@ -684,17 +684,17 @@ bool Edge::IntersectOverlapped(const Edge *f1, const Edge *f2, EdgeIntersector * */ void Edge::Interpolate1DLin(const std::vector& distrib1, const std::vector& distrib2, std::map >& result) { - int nbOfV1=distrib1.size()-1; - int nbOfV2=distrib2.size()-1; + std::size_t nbOfV1=distrib1.size()-1; + std::size_t nbOfV2=distrib2.size()-1; Node *n1=new Node(0.,0.); Node *n3=new Node(0.,0.); Node *n2=new Node(0.,0.); Node *n4=new Node(0.,0.); MergePoints commonNode; - for(int i=0;i::const_iterator iter=find_if(distrib2.begin()+1,distrib2.end(),bind2nd(std::greater_equal(),distrib1[i])); if(iter!=distrib2.end()) { - for(int j=(iter-1)-distrib2.begin();j& addNodes, const tmpp2[tmpp.size()+1]=endId; std::vector::iterator itt=std::unique(tmpp2.begin(),tmpp2.end()); tmpp2.resize(std::distance(tmpp2.begin(),itt)); - int nbOfEdges=tmpp2.size()-1; - for(int i=0;i& edgesOther, std::vector& addCoo, std::map& mapAddCoo) const { if (!_direction) - skipStartOrEnd *= -1; // invert value - see QuadraticPolygon::splitAbs() + skipStartOrEnd = (short)(-skipStartOrEnd); // invert value - see QuadraticPolygon::splitAbs() _ptr->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,skipStartOrEnd,edgesOther,addCoo,mapAddCoo); } diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx index 5ccc4c06b..c18c70791 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx @@ -324,7 +324,7 @@ void QuadraticPolygon::splitAbs(QuadraticPolygon& other, // std::map::const_iterator thisStart(mapThis.find(curThis->getStartNode())),thisEnd(mapThis.find(curThis->getEndNode())), otherStart(mapOther.find(curOtherTmp->getStartNode())),otherEnd(mapOther.find(curOtherTmp->getEndNode())); - int thisStart2(thisStart==mapThis.end()?-1:(*thisStart).second), thisEnd2(thisEnd==mapThis.end()?-1:(*thisEnd).second), + mcIdType thisStart2(thisStart==mapThis.end()?-1:(*thisStart).second), thisEnd2(thisEnd==mapThis.end()?-1:(*thisEnd).second), otherStart2(otherStart==mapOther.end()?-1:(*otherStart).second+offset1),otherEnd2(otherEnd==mapOther.end()?-1:(*otherEnd).second+offset1); // if(curThis->getPtr()->intersectWith(curOtherTmp->getPtr(),merge,*cThis,*cOther)) @@ -362,7 +362,7 @@ void QuadraticPolygon::splitAbs(QuadraticPolygon& other, // Converting back to integer connectivity: if(otherTmp._sub_edges.size()>1) // only if a new point has been added (i.e. an actual intersection was done) { - int jj = 0, sz(otherTmp._sub_edges.size()); + std::size_t jj = 0, sz(otherTmp._sub_edges.size()); for(std::list::const_iterator it=otherTmp._sub_edges.begin();it!=otherTmp._sub_edges.end();it++, jj++) { short skipStartOrEnd = jj == 0 ? -1 : (jj == sz-1 ? 1 : 0); // -1 means START, 1 means END, 0 other @@ -403,7 +403,7 @@ void QuadraticPolygon::appendEdgeFromCrudeDataArray(std::size_t edgePos, const s if(!isQuad) { bool direct=descBg[edgePos]>0; - mcIdType edgeId=abs(descBg[edgePos])-1; // back to C indexing mode + mcIdType edgeId=std::abs(descBg[edgePos])-1; // back to C indexing mode const std::vector& subEdge=intersectEdges[edgeId]; std::size_t nbOfSubEdges=subEdge.size()/2; for(std::size_t j=0;j0; - mcIdType edgeId=abs(descBg[edgePos])-1; + mcIdType edgeId=std::abs(descBg[edgePos])-1; const std::vector& subEdge=intersectEdges[edgeId]; std::size_t nbOfSubEdges=subEdge.size()/2; if(colinearity) @@ -478,7 +478,7 @@ void QuadraticPolygon::buildFromCrudeDataArray2(const std::map0; - mcIdType edgeId=abs(descBg[i])-1;//current edge id of pol2 + mcIdType edgeId=std::abs(descBg[i])-1;//current edge id of pol2 std::map >::const_iterator it1=alreadyExistingIn2.find(descBg[i]),it2=alreadyExistingIn2.find(-descBg[i]); if(it1!=alreadyExistingIn2.end() || it2!=alreadyExistingIn2.end()) { @@ -511,7 +511,7 @@ void QuadraticPolygon::buildFromCrudeDataArray2(const std::map >(edgeId1,std::pair(descBg1[j]>0,offset1)));// it exists an edge into pol1 given by tuple (idIn1,direct1) that is colinear at edge 'edgeId' in pol2 @@ -573,7 +573,7 @@ void QuadraticPolygon::buildFromCrudeDataArray2(const std::map reuse Edge instance of pol1 - ElementaryEdge *e=pol1[offset1+(direct1?offset2:nbOfSubEdges1-offset2-1)]; + ElementaryEdge *e=pol1[FromIdType(offset1+(direct1?offset2:nbOfSubEdges1-offset2-1))]; Edge *ee=e->getPtr(); ee->incrRef(); ElementaryEdge *e2=new ElementaryEdge(ee,!(direct1^direction11)); @@ -597,7 +597,7 @@ void QuadraticPolygon::updateLocOfEdgeFromCrudeDataArray2(const mcIdType *descBg for(std::size_t i=0;i0; - mcIdType edgeId=abs(descBg[i])-1;//current edge id of pol2 + mcIdType edgeId=std::abs(descBg[i])-1;//current edge id of pol2 const std::vector& c=colinear1[edgeId]; if(c.empty()) continue; @@ -608,7 +608,7 @@ void QuadraticPolygon::updateLocOfEdgeFromCrudeDataArray2(const mcIdType *descBg mcIdType offset1=0; for(std::size_t j=0;j(offset1+(direct1?offset2:nbOfSubEdges1-offset2-1))]; e->getPtr()->declareOn(); } } diff --git a/src/INTERP_KERNEL/InterpKernelCellSimplify.cxx b/src/INTERP_KERNEL/InterpKernelCellSimplify.cxx index 1fa6079c9..326baa5cf 100644 --- a/src/INTERP_KERNEL/InterpKernelCellSimplify.cxx +++ b/src/INTERP_KERNEL/InterpKernelCellSimplify.cxx @@ -66,7 +66,7 @@ INTERP_KERNEL::NormalizedCellType CellSimplify::simplifyDegeneratedCell(INTERP_K } else { - int quadOff = lgth/2; + mcIdType quadOff = lgth/2; mcIdType *tmpQuad = new mcIdType[quadOff]; for(int i = 0; i < quadOff; i++) if(conn[i] != conn[(i+1)%quadOff] || conn[i] != conn[i+quadOff]) // zip nul segments/arcs (quad point must match too) @@ -181,8 +181,8 @@ INTERP_KERNEL::NormalizedCellType CellSimplify::tryToUnPoly3D(const mcIdType *co { std::set nodes(conn,conn+lgth); nodes.erase(-1); - int nbOfNodes=(int)nodes.size(); - int magicNumber=100*nbOfNodes+nbOfFaces; + std::size_t nbOfNodes=nodes.size(); + mcIdType magicNumber=100*nbOfNodes+nbOfFaces; switch(magicNumber) { case 806: @@ -260,8 +260,8 @@ bool CellSimplify::orientOppositeFace(const mcIdType *baseFace, mcIdType *retCon std::vector< std::pair >::iterator it=std::find(oppEdges.begin(),oppEdges.end(),pInOpp); if(it==oppEdges.end())//the opposite edge of side face is not found opposite face ... maybe problem of orientation of polyhedron return false; - int pos2=(int)std::distance(oppEdges.begin(),it); - int offset=pos-pos2; + mcIdType pos2=std::distance(oppEdges.begin(),it); + mcIdType offset=pos-pos2; if(offset<0) offset+=lgthBaseFace; //this is the end copy the result @@ -451,7 +451,7 @@ INTERP_KERNEL::NormalizedCellType CellSimplify::tryToUnPolyPyra5(const mcIdType std::set quad4S(quad4,quad4+4); w=conn; bool ok=true; - int point=-1; + mcIdType point=-1; for(std::size_t i=0;i<5 && ok;i++) { if(i!=quad4_pos) @@ -496,7 +496,7 @@ INTERP_KERNEL::NormalizedCellType CellSimplify::tryToUnPolyTetra4(const mcIdType if(std::find_if(conn+lgth,conn+lgth+nbOfFaces,std::bind2nd(std::not_equal_to(),ToIdType(INTERP_KERNEL::NORM_TRI3)))==conn+lgth+nbOfFaces) { std::set tribase(conn,conn+3); - int point=-1; + mcIdType point=-1; bool ok=true; for(int i=1;i<4 && ok;i++) { diff --git a/src/INTERP_KERNEL/InterpolationOptions.cxx b/src/INTERP_KERNEL/InterpolationOptions.cxx index 63998d933..0d70a7d0a 100644 --- a/src/INTERP_KERNEL/InterpolationOptions.cxx +++ b/src/INTERP_KERNEL/InterpolationOptions.cxx @@ -255,7 +255,7 @@ std::string INTERP_KERNEL::InterpolationOptions::filterInterpolationMethod(const return std::string(meth); } -bool INTERP_KERNEL::InterpolationOptions::setInterpolationOptions(long print_level, +bool INTERP_KERNEL::InterpolationOptions::setInterpolationOptions(int print_level, std::string intersection_type, double precision, double median_plane, @@ -263,7 +263,7 @@ bool INTERP_KERNEL::InterpolationOptions::setInterpolationOptions(long print_lev double bounding_box_adjustment, double bounding_box_adjustment_abs, double max_distance_for_3Dsurf_intersect, - long orientation, + int orientation, bool measure_abs, std::string splitting_policy) { diff --git a/src/INTERP_KERNEL/InterpolationOptions.hxx b/src/INTERP_KERNEL/InterpolationOptions.hxx index d06c50964..f4fd8984d 100644 --- a/src/INTERP_KERNEL/InterpolationOptions.hxx +++ b/src/INTERP_KERNEL/InterpolationOptions.hxx @@ -98,7 +98,7 @@ namespace INTERP_KERNEL void init(); - bool setInterpolationOptions(long print_level, + bool setInterpolationOptions(int print_level, std::string intersection_type, double precision, double median_plane, @@ -106,7 +106,7 @@ namespace INTERP_KERNEL double bounding_box_adjustment, double bounding_box_adjustment_abs, double max_distance_for_3Dsurf_intersect, - long orientation, + int orientation, bool measure_abs, std::string splitting_policy); void copyOptions(const InterpolationOptions & other) { *this = other; } diff --git a/src/INTERP_KERNEL/SplitterTetra.cxx b/src/INTERP_KERNEL/SplitterTetra.cxx index 0d109f48d..d7453f5fd 100644 --- a/src/INTERP_KERNEL/SplitterTetra.cxx +++ b/src/INTERP_KERNEL/SplitterTetra.cxx @@ -197,17 +197,19 @@ namespace INTERP_KERNEL for(mcIdType i=0;i(nbOfNodesOfFace); + tmp[0]/=nbNF; tmp[1]/=nbNF; tmp[2]/=nbNF; tmp2[0]+=tmp[0]; tmp2[1]+=tmp[1]; tmp2[2]+=tmp[2]; work+=nbOfNodesOfFace+1; } - tmp2[0]/=nbOfFaces; tmp2[1]/=nbOfFaces; tmp2[2]/=nbOfFaces; + double nbF = FromIdType(nbOfFaces); + tmp2[0]/=nbF; tmp2[1]/=nbF; tmp2[2]/=nbF; return ; } default: diff --git a/src/INTERP_KERNEL/TransformedTriangleMath.cxx b/src/INTERP_KERNEL/TransformedTriangleMath.cxx index 6f896d28d..d55c994c9 100644 --- a/src/INTERP_KERNEL/TransformedTriangleMath.cxx +++ b/src/INTERP_KERNEL/TransformedTriangleMath.cxx @@ -146,7 +146,7 @@ namespace INTERP_KERNEL const long double delta = MULT_PREC_F * ( std::fabs(term1) + std::fabs(term2) ); - if( epsilonEqual(_doubleProducts[8*seg + dp], 0.0, THRESHOLD_F * delta)) + if( epsilonEqual(_doubleProducts[8*seg + dp], 0.0, (double)(THRESHOLD_F * delta))) { // debug output #if LOG_LEVEL >= 5 @@ -485,7 +485,7 @@ namespace INTERP_KERNEL const long double delta = MULT_PREC_F * (std::fabs(p_term) + std::fabs(q_term) + std::fabs(r_term)); #endif - if( epsilonEqual( p_term + q_term + r_term, 0.0, THRESHOLD_F * delta) ) + if( epsilonEqual( p_term + q_term + r_term, 0.0, (double)(THRESHOLD_F * delta)) ) { LOG(4, "Reset imprecise triple product for corner " << corner << " to zero" ); return 0.0;