Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make implicit narrowing conversions explicit #182

Open
vvolkl opened this issue Sep 17, 2021 · 0 comments
Open

Make implicit narrowing conversions explicit #182

vvolkl opened this issue Sep 17, 2021 · 0 comments

Comments

@vvolkl
Copy link
Contributor

vvolkl commented Sep 17, 2021

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);
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant