From 57847e625cf3a9fa8b43d0cf6722976093a83812 Mon Sep 17 00:00:00 2001 From: Barry Fowler Date: Tue, 30 Aug 2022 12:56:59 -0700 Subject: [PATCH] Fix GCC warnings with -Wshadow and -Wconversion: - suppressed -Wshadow in libraries, tutorials and regressions - suppressed -Wconversion when casts to simple POD type required --- examples/common/stopwatch.h | 5 +++-- opensubdiv/far/patchBuilder.cpp | 8 ++++---- opensubdiv/far/primvarRefiner.h | 11 ++++++++--- opensubdiv/far/topologyRefinerFactory.h | 4 ++-- opensubdiv/sdc/catmarkScheme.h | 6 ++++-- opensubdiv/sdc/options.h | 19 ++++++++++--------- regression/common/arg_utils.cpp | 2 +- regression/common/shape_utils.h | 2 +- regression/far_perf/far_perf.cpp | 7 ++----- 9 files changed, 35 insertions(+), 29 deletions(-) diff --git a/examples/common/stopwatch.h b/examples/common/stopwatch.h index 45601e2c..ef797cc2 100644 --- a/examples/common/stopwatch.h +++ b/examples/common/stopwatch.h @@ -43,14 +43,15 @@ public: void Start() { struct timeval l_rtime; gettimeofday(&l_rtime,0); - _elapsed = l_rtime.tv_sec + l_rtime.tv_usec/1000000.0; + _elapsed = (double)l_rtime.tv_sec + (double)l_rtime.tv_usec/1000000.0; } void Stop() { struct timeval l_rtime; gettimeofday(&l_rtime,0); - _elapsed = (l_rtime.tv_sec + l_rtime.tv_usec/1000000.0) - _elapsed; + _elapsed = ((double)l_rtime.tv_sec + (double)l_rtime.tv_usec/1000000.0) + - _elapsed; _totalElapsed += _elapsed; } diff --git a/opensubdiv/far/patchBuilder.cpp b/opensubdiv/far/patchBuilder.cpp index 248ccf56..34410679 100644 --- a/opensubdiv/far/patchBuilder.cpp +++ b/opensubdiv/far/patchBuilder.cpp @@ -221,10 +221,10 @@ namespace { ConstIndexArray vFaces = level.getVertexFaces(vIndex); ConstLocalIndexArray vInFaces = level.getVertexFaceLocalIndices(vIndex); - vSpan._startFace = vFaces.size(); + vSpan._startFace = (LocalIndex) vFaces.size(); for (int i = 0; i < vFaces.size(); ++i) { if ((vFaces[i] == startFace) && (vInFaces[i] == startCorner)) { - vSpan._startFace = i; + vSpan._startFace = (LocalIndex) i; break; } } @@ -1137,8 +1137,8 @@ PatchBuilder::assembleIrregularSourcePatch( } else { ConstIndexArray vFaces = level.getVertexFaces(fVerts[corner]); - patchCorner._numFaces = vFaces.size(); - patchCorner._patchFace = vFaces.FindIndex(faceIndex); + patchCorner._numFaces = (LocalIndex) vFaces.size(); + patchCorner._patchFace = (LocalIndex) vFaces.FindIndex(faceIndex); patchCorner._boundary = vTag._boundary; } patchCorner._sharp = cornerSpans[corner]._sharp; diff --git a/opensubdiv/far/primvarRefiner.h b/opensubdiv/far/primvarRefiner.h index 6fa82638..42abc528 100644 --- a/opensubdiv/far/primvarRefiner.h +++ b/opensubdiv/far/primvarRefiner.h @@ -969,9 +969,14 @@ PrimvarRefinerReal::interpFVarFromVerts(int level, T const & src, U & dst, Vtr::internal::FVarLevel::ConstValueTagArray pValueTags = parentFVar.getVertexValueTags(vert); Vtr::internal::FVarLevel::ConstValueTagArray cValueTags = childFVar.getVertexValueTags(cVert); - for (int cSibling = 0; cSibling < cVertValues.size(); ++cSibling) { - int pSibling = refineFVar.getChildValueParentSource(cVert, cSibling); - assert(pSibling == cSibling); + for (int cSiblingIndex = 0; cSiblingIndex < cVertValues.size(); ++cSiblingIndex) { + int pSiblingIndex = refineFVar.getChildValueParentSource(cVert, cSiblingIndex); + assert(pSiblingIndex == cSiblingIndex); + + typedef Vtr::internal::FVarLevel::Sibling SiblingIntType; + + SiblingIntType cSibling = (SiblingIntType) cSiblingIndex; + SiblingIntType pSibling = (SiblingIntType) pSiblingIndex; Vtr::Index pVertValue = pVertValues[pSibling]; Vtr::Index cVertValue = cVertValues[cSibling]; diff --git a/opensubdiv/far/topologyRefinerFactory.h b/opensubdiv/far/topologyRefinerFactory.h index 839180f2..8f3358e3 100644 --- a/opensubdiv/far/topologyRefinerFactory.h +++ b/opensubdiv/far/topologyRefinerFactory.h @@ -451,7 +451,7 @@ template inline void TopologyRefinerFactory::setNumBaseFaceVertices(TopologyRefiner & newRefiner, Index f, int count) { newRefiner._levels[0]->resizeFaceVertices(f, count); - newRefiner._hasIrregFaces |= (count != newRefiner._regFaceSize); + newRefiner._hasIrregFaces = newRefiner._hasIrregFaces || (count != newRefiner._regFaceSize); } template inline void @@ -553,7 +553,7 @@ template inline void TopologyRefinerFactory::setBaseFaceHole(TopologyRefiner & newRefiner, Index f, bool b) { newRefiner._levels[0]->setFaceHole(f, b); - newRefiner._hasHoles |= b; + newRefiner._hasHoles = newRefiner._hasHoles || b; } template diff --git a/opensubdiv/sdc/catmarkScheme.h b/opensubdiv/sdc/catmarkScheme.h index c724b4d5..bf9e7a7a 100644 --- a/opensubdiv/sdc/catmarkScheme.h +++ b/opensubdiv/sdc/catmarkScheme.h @@ -277,9 +277,11 @@ Scheme::assignSmoothLimitMask(VERTEX const& vertex, MASK& posMas posMask.FaceWeight(2) = fWeight; posMask.FaceWeight(3) = fWeight; } else { - Weight fWeight = 1.0f / (Weight)(valence * (valence + 5.0f)); + Weight Valence = (Weight) valence; + + Weight fWeight = 1.0f / (Valence * (Valence + 5.0f)); Weight eWeight = 4.0f * fWeight; - Weight vWeight = (Weight)(1.0f - valence * (eWeight + fWeight)); + Weight vWeight = 1.0f - Valence * (eWeight + fWeight); posMask.VertexWeight(0) = vWeight; for (int i = 0; i < valence; ++i) { diff --git a/opensubdiv/sdc/options.h b/opensubdiv/sdc/options.h index d368bc5f..fd4a1dff 100644 --- a/opensubdiv/sdc/options.h +++ b/opensubdiv/sdc/options.h @@ -89,33 +89,34 @@ public: VtxBoundaryInterpolation GetVtxBoundaryInterpolation() const { return (VtxBoundaryInterpolation) _vtxBoundInterp; } /// \brief Set vertex boundary interpolation rule - void SetVtxBoundaryInterpolation(VtxBoundaryInterpolation b) { _vtxBoundInterp = b; } + void SetVtxBoundaryInterpolation(VtxBoundaryInterpolation b) { _vtxBoundInterp = (EnumIntType) b; } /// \brief Get face-varying interpolation rule FVarLinearInterpolation GetFVarLinearInterpolation() const { return (FVarLinearInterpolation) _fvarLinInterp; } /// \brief Set face-varying interpolation rule - void SetFVarLinearInterpolation(FVarLinearInterpolation b) { _fvarLinInterp = b; } + void SetFVarLinearInterpolation(FVarLinearInterpolation b) { _fvarLinInterp = (EnumIntType) b; } /// \brief Get edge crease rule CreasingMethod GetCreasingMethod() const { return (CreasingMethod) _creasingMethod; } /// \brief Set edge crease rule - void SetCreasingMethod(CreasingMethod c) { _creasingMethod = c; } + void SetCreasingMethod(CreasingMethod c) { _creasingMethod = (EnumIntType) c; } /// \brief Get triangle subdivision weights rule (Catmark scheme only !) TriangleSubdivision GetTriangleSubdivision() const { return (TriangleSubdivision) _triangleSub; } /// \brief Set triangle subdivision weights rule (Catmark scheme only !) - void SetTriangleSubdivision(TriangleSubdivision t) { _triangleSub = t; } + void SetTriangleSubdivision(TriangleSubdivision t) { _triangleSub = (EnumIntType) t; } private: + // Use a small integer type to pack these rather than bitfields: + typedef unsigned char EnumIntType; - // Bitfield members: - unsigned int _vtxBoundInterp : 2, - _fvarLinInterp : 3, - _creasingMethod : 2, - _triangleSub : 2; + EnumIntType _vtxBoundInterp; + EnumIntType _fvarLinInterp; + EnumIntType _creasingMethod; + EnumIntType _triangleSub; }; } // end namespace sdc diff --git a/regression/common/arg_utils.cpp b/regression/common/arg_utils.cpp index 401f91f2..dd3b6013 100644 --- a/regression/common/arg_utils.cpp +++ b/regression/common/arg_utils.cpp @@ -33,7 +33,7 @@ static int parseIntArg(const char* argString, int dfltValue = 0) { char *argEndptr; - int argValue = strtol(argString, &argEndptr, 10); + int argValue = (int) strtol(argString, &argEndptr, 10); if (*argEndptr != 0) { printf("Warning: non-integer option parameter '%s' ignored\n", argString); diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index 07e9682b..74784773 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -122,7 +122,7 @@ struct Shape { char FindMaterial(char const * name) { for (int i=0; i<(int)mtls.size(); ++i) { if (mtls[i]->name==name) { - return i; + return (char) i; } } return -1; diff --git a/regression/far_perf/far_perf.cpp b/regression/far_perf/far_perf.cpp index 8838258e..9c3eed36 100644 --- a/regression/far_perf/far_perf.cpp +++ b/regression/far_perf/far_perf.cpp @@ -134,10 +134,7 @@ RunPerfTest(Shape const & shape, TestOptions const & options) { FarStencilTable const * vertexStencils = NULL; if (options.createStencils) { s.Start(); - - typename FarStencilTableFactory::Options options; - vertexStencils = FarStencilTableFactory::Create(*refiner, options); - + vertexStencils = FarStencilTableFactory::Create(*refiner); s.Stop(); result.timeStencilFactory = s.GetElapsed(); } else { @@ -273,7 +270,7 @@ PrintResultCSV(TestResult const & result, PrintOptions const & options) { static int parseIntArg(char const * argString, int dfltValue = 0) { char *argEndptr; - int argValue = strtol(argString, &argEndptr, 10); + int argValue = (int) strtol(argString, &argEndptr, 10); if (*argEndptr != 0) { fprintf(stderr, "Warning: non-integer option parameter '%s' ignored\n",