← Back to team overview

kicad-developers team mailing list archive

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

 

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 24c862577174450ba2a591797e2f6dd6b188e87c 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 +-
 2 files changed, 3 insertions(+), 3 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;
         }
-- 
2.17.1


Follow ups