]> OCCT Git - occt.git/commitdiff
Coding - Fixing warning for Clang #209
authordpasukhi <dpasukhi@opencascade.com>
Mon, 23 Dec 2024 18:28:17 +0000 (18:28 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Mon, 23 Dec 2024 21:12:11 +0000 (21:12 +0000)
Update CMake flags and override methods for improved compatibility
Enhance build configurations and improve code quality with compiler flags

12 files changed:
.github/workflows/build-and-test-multiplatform.yml
adm/cmake/occt_defs_flags.cmake
src/Aspect/Aspect_OpenVRSession.cxx
src/ExpToCasExe/exptocas.tab.cxx
src/IVtkDraw/IVtkDraw_Interactor.hxx
src/IVtkTools/IVtkTools_DisplayModeFilter.hxx
src/IVtkTools/IVtkTools_SubPolyDataFilter.hxx
src/QABugs/QABugs_11.cxx
src/ShapeProcess/ShapeProcess.cxx
src/ShapeProcess/ShapeProcess.hxx
src/StepFile/lex.step.cxx
src/StepFile/step.tab.cxx

index 9a3715798eb7f7acfc8b554e7cff3b29d634f01b..a93fd19170ab308a66d300fe72a0461d251d9af3 100644 (file)
@@ -71,7 +71,9 @@ jobs:
                 -D USE_VTK=ON `
                 -D USE_TBB=ON `
                 -D USE_RAPIDJSON=ON `
-                -D USE_OPENGL=ON ..
+                -D USE_OPENGL=ON `
+                -D CMAKE_CXX_FLAGS="/W4 /WX" `
+                -D CMAKE_C_FLAGS="/W4 /WX" ..
       shell: pwsh
 
     - name: Build OCCT
@@ -141,7 +143,9 @@ jobs:
                 -D USE_VTK=OFF `
                 -D USE_TBB=ON `
                 -D USE_RAPIDJSON=ON `
-                -D USE_OPENGL=ON ..
+                -D USE_OPENGL=ON `
+                -D CMAKE_CXX_FLAGS="-Werror -Wall -Wextra -Wno-unknown-warning-option" `
+                -D CMAKE_C_FLAGS="-Werror -Wall -Wextra -Wno-unknown-warning-option" ..
       shell: pwsh
 
     - name: Build OCCT
@@ -193,7 +197,9 @@ jobs:
               -D USE_DRACO=ON \
               -D USE_FREETYPE=ON \
               -D USE_OPENGL=ON \
-              -D USE_FREEIMAGE=ON ..
+              -D USE_FREEIMAGE=ON \
+              -D CMAKE_CXX_FLAGS="-Werror -Wall -Wextra" \
+              -D CMAKE_C_FLAGS="-Werror -Wall -Wextra" ..
 
     - name: Build OCCT
       run: |
@@ -244,7 +250,9 @@ jobs:
               -D USE_DRACO=ON \
               -D USE_FREETYPE=ON \
               -D USE_OPENGL=ON \
-              -D USE_FREEIMAGE=ON ..
+              -D USE_FREEIMAGE=ON \
+              -D CMAKE_CXX_FLAGS="-Werror -Wall -Wextra" \
+              -D CMAKE_C_FLAGS="-Werror -Wall -Wextra" ..
 
     - name: Build OCCT
       run: |
@@ -298,7 +306,9 @@ jobs:
               -D USE_VTK=ON \
               -D USE_TBB=OFF \
               -D USE_RAPIDJSON=ON \
-              -D USE_OPENGL=ON ..
+              -D USE_OPENGL=ON \
+              -D CMAKE_CXX_FLAGS="-Werror -Wall -Wextra" \
+              -D CMAKE_C_FLAGS="-Werror -Wall -Wextra" ..
 
     - name: Build OCCT
       run: |
index de5d59643f1674322f9f4db552e00440ee3fb61a..8018cc4a0ccc2684cdd27e6a0bb0f06d3ff94c6a 100644 (file)
@@ -38,6 +38,10 @@ else()
   else()
    add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
   endif()
+  if (APPLE)
+    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
+    set (CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   -Wno-deprecated-declarations")
+  endif()
   add_definitions(-DOCC_CONVERT_SIGNALS)
 endif()
 
@@ -152,9 +156,14 @@ elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPIL
 
     # Link-Time Code Generation(LTCG) is requared for Whole Program Optimisation(GL)
     set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
-    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto -Wl,--gc-sections")
-    set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} -flto -Wl,--gc-sections")
-    set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -flto -Wl,--gc-sections")
+    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto")
+    set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} -flto")
+    set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -flto")
+    if (NOT WIN32)
+      set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--gc-sections")
+      set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} -Wl,--gc-sections")
+      set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -Wl,--gc-sections")
+    endif()
   endif()
   if (CMAKE_CXX_COMPILER_ID MATCHES "[Cc][Ll][Aa][Nn][Gg]")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshorten-64-to-32")
@@ -173,8 +182,10 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "[Cc][Ll][Aa][Nn][Gg]")
     # CLang can be used with both libstdc++ and libc++, however on OS X libstdc++ is outdated.
     set (CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
   endif()
-  # Optimize size of binaries
-  set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "-Wl,-s ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
+  if (NOT WIN32)
+    # Optimize size of binaries
+    set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "-Wl,-s ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
+  endif()
 endif()
 if(MINGW)
   add_definitions(-D_WIN32_WINNT=0x0601)
@@ -183,7 +194,7 @@ if(MINGW)
   # workaround bugs in mingw with vtable export
   set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols")
 endif()
-if (DEFINED CMAKE_COMPILER_IS_GNUCXX)
+if (CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE)
   # Optimize size of binaries
   set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
   set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
index 2c295435f6a9821f0beb3c6a2a63d351339a4c66..0ff1fdc019be75143502de150e5ffb5e13358fb0 100644 (file)
@@ -1038,14 +1038,12 @@ void Aspect_OpenVRSession::ProcessEvents()
       {
         case Aspect_XRActionType_InputDigital:
         {
-          Aspect_XRDigitalActionData aData = GetDigitalActionData (anAction);
-          //if (aData.IsChanged) { std::cout << "  " << anAction->Id() << " pressed: " << aData.IsPressed << "\n"; }
+          GetDigitalActionData (anAction);
           break;
         }
         case Aspect_XRActionType_InputAnalog:
         {
-          Aspect_XRAnalogActionData aData = GetAnalogActionData (anAction);
-          //if (aData.IsChanged()) { std::cout << "  " << anAction->Id() << " changed: " << aData.VecXYZ[0] << " " << aData.VecXYZ[1] << " " << aData.VecXYZ[2] << "\n"; }
+          GetAnalogActionData (anAction);
           break;
         }
         case Aspect_XRActionType_InputPose:
@@ -1053,6 +1051,8 @@ void Aspect_OpenVRSession::ProcessEvents()
           GetPoseActionDataForNextFrame (anAction);
           break;
         }
+        default:
+          break;
       }
     }
   }
index f213ed2006cf3f73ef53a85a4d5c80a4fe1f5f6e..725caec05ac498378f86be0906f4f42de96310d8 100644 (file)
@@ -496,7 +496,6 @@ namespace exptocas {
     int yylen = 0;
 
     // Error handling.
-    int yynerrs_ = 0;
     int yyerrstatus_ = 0;
 
     /// The lookahead symbol.
@@ -933,7 +932,6 @@ namespace exptocas {
     // If not already recovering from an error, report this error.
     if (!yyerrstatus_)
       {
-        ++yynerrs_;
         std::string msg = YY_("syntax error");
         error (YY_MOVE (msg));
       }
index f81d659d3b7aa5ad7fcc59ec559bbd701e5950e1..199bc3ff4277af681ad7e9e38f5afc532b85631e 100644 (file)
@@ -49,9 +49,9 @@ public:
 
   vtkTypeMacro (IVtkDraw_Interactor, vtkRenderWindowInteractor)
 
-  virtual void Initialize();
-  virtual void Enable();
-  virtual void Start() { }
+  virtual void Initialize() Standard_OVERRIDE;
+  virtual void Enable() Standard_OVERRIDE;
+  virtual void Start() Standard_OVERRIDE { }
 
   const PSelector& Selector() const { return mySelector; }
   void SetShapePicker (const PSelector& theSelector);
@@ -97,7 +97,7 @@ protected:
   void OnMouseWheelBackward (HWND wnd, UINT nFlags, Standard_Integer X, Standard_Integer Y);
 #else
   static void ProcessEvents (ClientData theData, int);
-  void GetMousePosition (Standard_Integer *theX, Standard_Integer *theY);
+  void GetMousePosition (Standard_Integer *theX, Standard_Integer *theY) Standard_OVERRIDE;
 #endif
 
 private:
index 72ee21188ac0691f7fa54af1df28eb13d1758947..31520a9ceff55ef609276b3a6ffd0c172ef39a5b 100644 (file)
@@ -35,7 +35,7 @@ public:
   vtkTypeMacro(IVtkTools_DisplayModeFilter,IVtkTools_SubPolyDataFilter)
 
   static IVtkTools_DisplayModeFilter *New();
-  void PrintSelf (std::ostream& os, vtkIndent indent);
+  void PrintSelf (std::ostream& os, vtkIndent indent) Standard_OVERRIDE;
 
   //! Set display mode to define cells types to be passed through this filter.
   void SetDisplayMode (const IVtk_DisplayMode aMode);
index 709f08823df6870f8af80f53d7c6359b30914c46..cbdff5af7988574af960235bcc304015885480c4 100644 (file)
@@ -35,7 +35,7 @@ public:
   vtkTypeMacro(IVtkTools_SubPolyDataFilter,vtkPolyDataAlgorithm)
 
   static IVtkTools_SubPolyDataFilter *New();
-  void PrintSelf (std::ostream& theOs, vtkIndent theIndent);
+  void PrintSelf (std::ostream& theOs, vtkIndent theIndent) Standard_OVERRIDE;
 
   //! Set ids to be passed through this filter.
   void SetData(const IVtk_IdTypeMap theSet);
index 6750ed5f299f9b627020a55c89c4809b6b7e628d..e90300e9c41887bf352f54962abb416cbfe85e88 100644 (file)
@@ -2193,13 +2193,18 @@ static Standard_Integer OCC6143 (Draw_Interpretor& di, Standard_Integer argc, co
 #elif defined(__GNUC__)
   #pragma GCC diagnostic push
   #pragma GCC diagnostic ignored "-Woverflow"
+#elif defined(_MSC_VER)
+  #pragma warning(push)
+  #pragma warning(disable: 4307)
 #endif
-      constexpr Standard_Integer i=IntegerLast();
+      constexpr Standard_Integer i = IntegerLast();
       Standard_Integer res = i + 1;
 #if defined(__clang__)
   #pragma clang diagnostic pop
 #elif defined(__GNUC__)
   #pragma GCC diagnostic pop
+#elif defined(_MSC_VER)
+  #pragma warning(pop)
 #endif
       di << "Not caught: " << i << " + 1 = " << res << ", still OK\n";
     }
index d8bf36688ea955196f5e9e36087ae36155b36b01..c9949d5749cbd54a0af5110c4219d216c855b8d8 100644 (file)
@@ -225,7 +225,7 @@ Standard_Boolean ShapeProcess::Perform(const Handle(ShapeProcess_Context)& theCo
 std::vector<std::pair<const char*, Handle(ShapeProcess_Operator)>> ShapeProcess::getOperators(const OperationsFlags& theFlags)
 {
   std::vector<std::pair<const char*, Handle(ShapeProcess_Operator)>> aResult;
-  for (std::underlying_type<Operation>::type anOperation = Operation::First; anOperation < Operation::Count; ++anOperation)
+  for (std::underlying_type<Operation>::type anOperation = Operation::First; anOperation <= Operation::Last; ++anOperation)
   {
     if (theFlags.test(anOperation))
     {
index ac4d9fab94a1e3045b9a837fc3cc388e80eeb803..d01846b63481eb8d5d03114e4b2b088067a3e78f 100644 (file)
@@ -61,7 +61,7 @@ public:
     FixShape,
     SplitClosedEdges,
     SplitCommonVertex,
-    Count // Number of operations.
+    Last = SplitCommonVertex // Last operation index.
   };
 
   // Bitset of operations. It is used to specify which operations should be performed.
@@ -70,7 +70,7 @@ public:
   // flags.set(ShapeProcess::Operation::DirectFaces);
   // flags.set(ShapeProcess::Operation::SameParameter);
   // ShapeProcess::Perform(context, flags);
-  using OperationsFlags = std::bitset<Operation::Count>;
+  using OperationsFlags = std::bitset<Operation::Last + 1>;
   
 public:
   //! Registers operator to make it visible for Performer
index bbbbbc310c91967379d4cc695bf6411f30582a32..2436b0f00801f9f2abaf9d1d74c2ab40190d15cc 100644 (file)
@@ -1318,7 +1318,7 @@ int yyFlexLexer::LexerInput( char* buf, int max_size )
        if ( yyin.bad() )
                return -1;
        else
-               return yyin.gcount();
+               return static_cast<int>(yyin.gcount());
 #endif
 }
 
index 7ce8463992c134050a1eacca58542546b04064bf..e86fbf346e54503ff200d274be18df6f4414f5cd 100644 (file)
@@ -437,7 +437,6 @@ namespace step {
     int yylen = 0;
 
     // Error handling.
-    int yynerrs_ = 0;
     int yyerrstatus_ = 0;
 
     /// The lookahead symbol.
@@ -681,7 +680,6 @@ namespace step {
     // If not already recovering from an error, report this error.
     if (!yyerrstatus_)
       {
-        ++yynerrs_;
         context yyctx (*this, yyla);
         std::string msg = yysyntax_error_ (yyctx);
         error (YY_MOVE (msg));