Skip to content

Make implicit narrowing conversions explicit #182

Description

@vvolkl

There are numerous occasions in cepcsw where a double is implicitly converted to a float. Newer compilers treat this as an error (-W-c++11-narrowing)

I have added the -W-no-c++11-narrowing to the recipe, but it's probably good practice to explicitly add the casts at one point (I started, but there are quite a few instances and this is not very urgent), for example:

diff --git a/Digitisers/SimpleDigi/src/TPCDigiAlg.cpp b/Digitisers/SimpleDigi/src/TPCDigiAlg.cpp
index ebb1df4..6aaa5f1 100644
--- a/Digitisers/SimpleDigi/src/TPCDigiAlg.cpp
+++ b/Digitisers/SimpleDigi/src/TPCDigiAlg.cpp
@@ -1231,12 +1231,13 @@ void TPCDigiAlg::writeVoxelToHit( Voxel_tpc* aVoxel){
   }
   debug() << "==============" << endmsg;
   // For no error in R
-  std::array<float,TRKHITNCOVMATRIX> covMat={sin(unsmearedPhi)*sin(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes,
-    -cos(unsmearedPhi)*sin(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes,
-    cos(unsmearedPhi)*cos(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes,
-    0.,
-    0.,
-    float(tpcZRes*tpcZRes)};
+    std::array<float,TRKHITNCOVMATRIX> covMat=
+        {static_cast<float>(sin(unsmearedPhi)*sin(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes),
+         static_cast<float>(-cos(unsmearedPhi)*sin(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes),
+         static_cast<float>(cos(unsmearedPhi)*cos(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes),
+         0.,
+         0.,
+         static_cast<float>(tpcZRes*tpcZRes)};
 
   trkHit.setCovMatrix(covMat);
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions