From 792109064b6a193c10c95a2fd32a9b0884491235 Mon Sep 17 00:00:00 2001
From: Nora Abi Akar <nora.abiakar@gmail.com>
Date: Mon, 9 Nov 2020 15:16:14 +0100
Subject: [PATCH] add throw (#1222)

Addresses some of the warnings from static analysis tools in #1084

* fix some instances where exceptions were constructed, but not thrown
* fix use-after-move in a unit test.
---
 arbor/benchmark_cell_group.cpp    | 2 +-
 arbor/spike_source_cell_group.cpp | 2 +-
 example/brunel/brunel.cpp         | 2 +-
 test/unit/test_simd.cpp           | 6 ++++--
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/arbor/benchmark_cell_group.cpp b/arbor/benchmark_cell_group.cpp
index 4c24ff42..c6a6e258 100644
--- a/arbor/benchmark_cell_group.cpp
+++ b/arbor/benchmark_cell_group.cpp
@@ -86,7 +86,7 @@ void benchmark_cell_group::add_sampler(sampler_association_handle h,
                                    sampler_function fn,
                                    sampling_policy policy)
 {
-    std::logic_error("A benchmark_cell group doen't support sampling of internal state!");
+    throw std::logic_error("A benchmark_cell group doen't support sampling of internal state!");
 }
 
 } // namespace arb
diff --git a/arbor/spike_source_cell_group.cpp b/arbor/spike_source_cell_group.cpp
index 0e3b3ba8..7abba54e 100644
--- a/arbor/spike_source_cell_group.cpp
+++ b/arbor/spike_source_cell_group.cpp
@@ -64,7 +64,7 @@ void spike_source_cell_group::clear_spikes() {
 }
 
 void spike_source_cell_group::add_sampler(sampler_association_handle, cell_member_predicate, schedule, sampler_function, sampling_policy) {
-    std::logic_error("A spike_source_cell group doen't support sampling of internal state!");
+    throw std::logic_error("A spike_source_cell group doen't support sampling of internal state!");
 }
 
 } // namespace arb
diff --git a/example/brunel/brunel.cpp b/example/brunel/brunel.cpp
index 03f63e8e..3e595d57 100644
--- a/example/brunel/brunel.cpp
+++ b/example/brunel/brunel.cpp
@@ -93,7 +93,7 @@ public:
         ncells_exc_(nexc), ncells_inh_(ninh), delay_(delay), seed_(seed) {
         // Make sure that in_degree_prop in the interval (0, 1]
         if (in_degree_prop <= 0.0 || in_degree_prop > 1.0) {
-            std::out_of_range("The proportion of incoming connections should be in the interval (0, 1].");
+            throw std::out_of_range("The proportion of incoming connections should be in the interval (0, 1].");
         }
 
         // Set up the parameters.
diff --git a/test/unit/test_simd.cpp b/test/unit/test_simd.cpp
index 67ac6a1a..94bf37e8 100644
--- a/test/unit/test_simd.cpp
+++ b/test/unit/test_simd.cpp
@@ -129,8 +129,9 @@ TYPED_TEST_P(simd_value, elements) {
     EXPECT_TRUE(testing::indexed_eq_n(N, bv, b));
 
     // array rvalue initialization:
+    auto cv_copy = cv;
     simd c(std::move(cv));
-    EXPECT_TRUE(testing::indexed_eq_n(N, cv, c));
+    EXPECT_TRUE(testing::indexed_eq_n(N, cv_copy, c));
 
     // pointer initialization:
     simd d(&dv[0]);
@@ -415,8 +416,9 @@ TYPED_TEST_P(simd_value, mask_elements) {
         EXPECT_TRUE(testing::indexed_eq_n(N, bv, b));
 
         // array rvalue initialization:
+        auto cv_copy = cv;
         mask c(std::move(cv));
-        EXPECT_TRUE(testing::indexed_eq_n(N, cv, c));
+        EXPECT_TRUE(testing::indexed_eq_n(N, cv_copy, c));
 
         // pointer initialization:
         mask d(&dv[0]);
-- 
GitLab