[PATCH] tests: fix compilation warning in tests/tst-run.cc

6 views
Skip to first unread message

Nadav Har'El

unread,
Nov 28, 2019, 3:44:28 AM11/28/19
to osv...@googlegroups.com, Nadav Har'El
It is generally a bad idea to catch exceptions by value, because it
forces an unnecessary copy of the caught value. It's even worse when
the type is polymorphic - in that case the copy will only be a slice
of the original type. This is why recent compilers started to warn
when code catches a polymorphic type by value.

In the specific case fixed here, the warning is spurious, because the
caught exception isn't even used. But it's trivial to fix it, and get
rid of one more warning during test compilation.

Refs #976

Signed-off-by: Nadav Har'El <n...@scylladb.com>
---
tests/tst-run.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/tst-run.cc b/tests/tst-run.cc
index 3f1139c3..2a9a8f51 100644
--- a/tests/tst-run.cc
+++ b/tests/tst-run.cc
@@ -44,7 +44,7 @@ int main(int ac, char** av)
osv::run("/nonexistant.so", 0, nullptr, nullptr);
// should throw and not get here
report(false, "Run nonexistant");
- } catch(osv::launch_error) {
+ } catch(osv::launch_error&) {
report(true, "Run nonexistant");
}

--
2.21.0

Commit Bot

unread,
Nov 28, 2019, 10:02:34 AM11/28/19
to osv...@googlegroups.com, Nadav Har'El
From: Nadav Har'El <n...@scylladb.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

tests: fix compilation warning in tests/tst-run.cc

It is generally a bad idea to catch exceptions by value, because it
forces an unnecessary copy of the caught value. It's even worse when
the type is polymorphic - in that case the copy will only be a slice
of the original type. This is why recent compilers started to warn
when code catches a polymorphic type by value.

In the specific case fixed here, the warning is spurious, because the
caught exception isn't even used. But it's trivial to fix it, and get
rid of one more warning during test compilation.

Refs #976

Signed-off-by: Nadav Har'El <n...@scylladb.com>
Message-Id: <2019112808442...@scylladb.com>

---
diff --git a/tests/tst-run.cc b/tests/tst-run.cc
Reply all
Reply to author
Forward
0 new messages