tpaviot / oce

OpenCASCADE Community Edition (OCE): a community driven fork of the Open CASCADE library.
http://groups.google.com/group/oce-dev
GNU Lesser General Public License v2.1
811 stars 284 forks source link

Fix implicit conversion bug in C++11 #732

Open hannesweisbach opened 4 years ago

hannesweisbach commented 4 years ago

I'm compiling opencascade oce on macOS 10.15.6 with clang-7 under Nix. clang-7 uses the "gnu++14" language standard for C++ by default, if nothing else is specified. I couldn't find that opencascade oce requests an explicit C++ standard for compilation. IVtkVTK_ShapeData.cxx contains a narrowing non-constant cast in an initializer lists, which is illegal in C++11 and above. I fixed it by making it an explicit cast:

../src/IVtkVTK/IVtkVTK_ShapeData.cxx:107:28: error: non-constant-expression cannot be narrowed from type 'IVtk_PointId' (aka 'unsigned long') to 'vtkIdType' (aka 'long long') in initializer list [-Wc++11-narrowing]
  vtkIdType aPoints[2] = { thePointId1, thePointId2 };
                           ^~~~~~~~~~~
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:107:28: note: insert an explicit cast to silence this issue
  vtkIdType aPoints[2] = { thePointId1, thePointId2 };
                           ^~~~~~~~~~~
                           static_cast<vtkIdType>( )
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:107:41: error: non-constant-expression cannot be narrowed from type 'IVtk_PointId' (aka 'unsigned long') to 'vtkIdType' (aka 'long long') in initializer list [-Wc++11-narrowing]
  vtkIdType aPoints[2] = { thePointId1, thePointId2 };
                                        ^~~~~~~~~~~
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:107:41: note: insert an explicit cast to silence this issue
  vtkIdType aPoints[2] = { thePointId1, thePointId2 };
                                        ^~~~~~~~~~~
                                        static_cast<vtkIdType>( )
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:168:28: error: non-constant-expression cannot be narrowed from type 'IVtk_PointId' (aka 'unsigned long') to 'vtkIdType' (aka 'long long') in initializer list [-Wc++11-narrowing]
  vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
                           ^~~~~~~~~~~
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:168:28: note: insert an explicit cast to silence this issue
  vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
                           ^~~~~~~~~~~
                           static_cast<vtkIdType>( )
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:168:41: error: non-constant-expression cannot be narrowed from type 'IVtk_PointId' (aka 'unsigned long') to 'vtkIdType' (aka 'long long') in initializer list [-Wc++11-narrowing]
  vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
                                        ^~~~~~~~~~~
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:168:41: note: insert an explicit cast to silence this issue
  vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
                                        ^~~~~~~~~~~
                                        static_cast<vtkIdType>( )
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:168:54: error: non-constant-expression cannot be narrowed from type 'IVtk_PointId' (aka 'unsigned long') to 'vtkIdType' (aka 'long long') in initializer list [-Wc++11-narrowing]
  vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
                                                     ^~~~~~~~~~~
../src/IVtkVTK/IVtkVTK_ShapeData.cxx:168:54: note: insert an explicit cast to silence this issue
  vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
                                                     ^~~~~~~~~~~
                                                     static_cast<vtkIdType>( )