← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Fix 'catching polymorphic type by value' warnings

 

Hi,

Sorry, I missed one out in kicad/import_project.cpp

Cheers,

John

On Tue, Jun 5, 2018 at 8:43 AM, John Beard <john.j.beard@xxxxxxxxx> wrote:

> Hi,
>
> Small patch to fix some warnings (GCC 8.1.0) like this:
>
> warning: catching polymorphic type ‘class std::out_of_range’ by value
> [-Wcatch-value=]
>          catch( std::out_of_range )
>                      ^~~~~~~~~~~~
>
> Fixed by changing to catch-by-reference: "catch( const std:::out_of_range&
> )"
>
> C.f. recent commit ff1802d7a "Fix Coverity "Big parameter passed by value"
> warnings".
>
> As one of these fixes is in view.h, the warning came up a fair bit.
>
> Cheers,
>
> John
>
From dfe24f872bcc9665efbddd949e19a538258b5e12 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Tue, 5 Jun 2018 08:38:49 +0100
Subject: [PATCH] Common: Fix -Wcatch-value warnings (catching exceptions by
 value)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes some warnings on GCC 8.1:

warning: catching polymorphic type ‘class std::out_of_range’ by value [-Wcatch-value=]
         catch( std::out_of_range )
                     ^~~~~~~~~~~~

This fix is along the same lines as:

* ff1802d7a "Fix Coverity "Big parameter passed by value" warnings"
---
 common/view/view.cpp     | 4 ++--
 include/view/view.h      | 2 +-
 kicad/import_project.cpp | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/view/view.cpp b/common/view/view.cpp
index d4e22ff6b..84f848cd4 100644
--- a/common/view/view.cpp
+++ b/common/view/view.cpp
@@ -207,7 +207,7 @@ private:
             {
                 new_layer = aReorderMap.at( orig_layer );
             }
-            catch( std::out_of_range ) {}
+            catch( const std::out_of_range& ) {}
 
             m_groups[i].first = new_layer;
         }
@@ -665,7 +665,7 @@ void VIEW::ReorderLayerData( std::unordered_map<int, int> aReorderMap )
         {
             new_idx = aReorderMap.at( orig_idx );
         }
-        catch( std::out_of_range )
+        catch( const std::out_of_range& )
         {
             new_idx = orig_idx;
         }
diff --git a/include/view/view.h b/include/view/view.h
index 1397b4d54..3938bfdf8 100644
--- a/include/view/view.h
+++ b/include/view/view.h
@@ -590,7 +590,7 @@ public:
         {
             return m_layers.at( aLayer ).target == TARGET_CACHED;
         }
-        catch( std::out_of_range )
+        catch( const std::out_of_range& )
         {
             return false;
         }
diff --git a/kicad/import_project.cpp b/kicad/import_project.cpp
index 4f9d04360..3bcc7bb9f 100644
--- a/kicad/import_project.cpp
+++ b/kicad/import_project.cpp
@@ -165,7 +165,7 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event )
             {
                 pcbframe = Kiway.Player( FRAME_PCB, true );
             }
-            catch( IO_ERROR err )
+            catch( const IO_ERROR& err )
             {
                 wxMessageBox( _( "Pcbnew failed to load:\n" ) + err.What(), _( "KiCad Error" ),
                         wxOK | wxICON_ERROR, this );
-- 
2.17.1


Follow ups

References