]> sigrok.org Git - pulseview.git/commitdiff
fix catching polymorphic types by value
authorDan Horák <redacted>
Fri, 23 Mar 2018 20:33:18 +0000 (21:33 +0100)
committerDan Horák <redacted>
Fri, 23 Mar 2018 21:18:40 +0000 (22:18 +0100)
Compiling with GCC 8 produces a new warning about catching polymorphic
types by value. Proper way is to use references instead.

/home/sharkcz/projects/pulseview/main.cpp: In function ‘int main(int, char**)’:
/home/sharkcz/projects/pulseview/main.cpp:229:22: error: catching polymorphic type ‘class std::exception’ by value [-Werror=catch-value=]
   } catch (exception e) {
                      ^
cc1plus: all warnings being treated as errors

12 files changed:
main.cpp
pv/binding/device.cpp
pv/data/decodesignal.cpp
pv/data/signalbase.cpp
pv/devices/inputfile.cpp
pv/popups/channels.cpp
pv/session.cpp
pv/storesession.cpp
pv/toolbars/mainbar.cpp
pv/views/trace/analogsignal.cpp
pv/views/trace/decodetrace.cpp
pv/views/trace/logicsignal.cpp

index cd7e65d3cbbffa6d7a8ec949e02134c74af64c97..1e214e03f97df04c1f694b971ca25df0a36cc3eb 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -226,7 +226,7 @@ int main(int argc, char *argv[])
                        // Run the application
                        ret = a.exec();
 
-               } catch (exception e) {
+               } catch (exception& e) {
                        qDebug() << e.what();
                }
 
index 1afc2ce2f32c7f3009aec2296231b019fb15e8b8..df83f082e355d1c1ecc3c106d4055075cd9123b4 100644 (file)
@@ -68,7 +68,7 @@ Device::Device(shared_ptr<sigrok::Configurable> configurable) :
                string name_str;
                try {
                        name_str = key->description();
-               } catch (Error e) {
+               } catch (Error& e) {
                        name_str = key->name();
                }
 
index 5fbc8b6ca630bab38093f61f4a3e230feea366d2..77b2061c6e3b793d554613158761d7707a7af127 100644 (file)
@@ -361,7 +361,7 @@ int64_t DecodeSignal::get_working_sample_count(uint32_t segment_id) const
                        try {
                                const shared_ptr<LogicSegment> segment = logic_data->logic_segments().at(segment_id);
                                count = min(count, (int64_t)segment->get_sample_count());
-                       } catch (out_of_range) {
+                       } catch (out_of_range&) {
                                return 0;
                        }
                }
@@ -378,7 +378,7 @@ int64_t DecodeSignal::get_decoded_sample_count(uint32_t segment_id) const
        try {
                const DecodeSegment *segment = &(segments_.at(segment_id));
                result = segment->samples_decoded;
-       } catch (out_of_range) {
+       } catch (out_of_range&) {
                // Do nothing
        }
 
@@ -431,7 +431,7 @@ void DecodeSignal::get_annotation_subset(
                if (iter != rows->end())
                        (*iter).second.get_annotation_subset(dest,
                                start_sample, end_sample);
-       } catch (out_of_range) {
+       } catch (out_of_range&) {
                // Do nothing
        }
 }
@@ -607,7 +607,7 @@ uint32_t DecodeSignal::get_input_samplerate(uint32_t segment_id) const
                        try {
                                const shared_ptr<LogicSegment> segment = logic_data->logic_segments().at(segment_id);
                                samplerate = segment->samplerate();
-                       } catch (out_of_range) {
+                       } catch (out_of_range&) {
                                // Do nothing
                        }
                        break;
@@ -736,7 +736,7 @@ void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, c
                        shared_ptr<LogicSegment> segment;
                        try {
                                segment = logic_data->logic_segments().at(segment_id);
-                       } catch (out_of_range) {
+                       } catch (out_of_range&) {
                                qDebug() << "Muxer error for" << name() << ":" << ch.assigned_signal->name() \
                                        << "has no logic segment" << segment_id;
                                return;
@@ -756,7 +756,7 @@ void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, c
        shared_ptr<LogicSegment> output_segment;
        try {
                output_segment = logic_mux_data_->logic_segments().at(segment_id);
-       } catch (out_of_range) {
+       } catch (out_of_range&) {
                qDebug() << "Muxer error for" << name() << ": no logic mux segment" \
                        << segment_id << "in mux_logic_samples(), mux segments size is" \
                        << logic_mux_data_->logic_segments().size();
@@ -948,7 +948,7 @@ void DecodeSignal::decode_proc()
 
                                try {
                                        input_segment = logic_mux_data_->logic_segments().at(current_segment_id_);
-                               } catch (out_of_range) {
+                               } catch (out_of_range&) {
                                        qDebug() << "Decode error for" << name() << ": no logic mux segment" \
                                                << current_segment_id_ << "in decode_proc(), mux segments size is" \
                                                << logic_mux_data_->logic_segments().size();
index 54063b1d236bc1eff9a8ca1e44ad76aa95409cae..2972d4043cf7a7bb3e6b48b49e9b190589b92884 100644 (file)
@@ -219,7 +219,7 @@ bool SignalBase::segment_is_complete(uint32_t segment_id) const
                auto segments = data->analog_segments();
                try {
                        result = segments.at(segment_id)->is_complete();
-               } catch (out_of_range) {
+               } catch (out_of_range&) {
                        // Do nothing
                }
        }
@@ -230,7 +230,7 @@ bool SignalBase::segment_is_complete(uint32_t segment_id) const
                auto segments = data->logic_segments();
                try {
                        result = segments.at(segment_id)->is_complete();
-               } catch (out_of_range) {
+               } catch (out_of_range&) {
                        // Do nothing
                }
        }
@@ -617,7 +617,7 @@ void SignalBase::conversion_thread_proc()
 
                        try {
                                asegment = analog_data->analog_segments().at(segment_id).get();
-                       } catch (out_of_range) {
+                       } catch (out_of_range&) {
                                qDebug() << "Conversion error for" << name() << ": no analog segment" \
                                        << segment_id << ", segments size is" << analog_data->analog_segments().size();
                                return;
index 58c60d700bbd25375222b20f09c7f35a41097e3a..b866deb8245ed1d6051833f897efc2b7d59ee282 100644 (file)
@@ -74,7 +74,7 @@ void InputFile::open()
 
        try {
                device_ = input_->device();
-       } catch (sigrok::Error) {
+       } catch (sigrok::Error&) {
                return;
        }
 
index 3fb90ae760bac81287b6850353d06809dea01c5e..10146741224651594086b8c514b892f2ce2c20b2 100644 (file)
@@ -208,7 +208,7 @@ void Channels::showEvent(QShowEvent *event)
                try {
                        QLabel* label = group_label_map_.at(group);
                        label->setText(QString("<h3>%1</h3>").arg(group->name().c_str()));
-               } catch (out_of_range) {
+               } catch (out_of_range&) {
                        // Do nothing
                }
        }
index b1ce14680bbec848f6ae92fd3ec4010094d8320c..008ee6a282cc3ba326abe6b106a503576d7d753c 100644 (file)
@@ -521,7 +521,7 @@ void Session::load_file(QString file_name,
                                new devices::SessionFile(
                                        device_manager_.context(),
                                        file_name.toStdString())));
-       } catch (Error e) {
+       } catch (Error& e) {
                main_bar_->session_error(tr("Failed to load ") + file_name, e.what());
                set_default_device();
                main_bar_->update_device_list();
@@ -732,7 +732,7 @@ shared_ptr<data::DecodeSignal> Session::add_decode_signal()
                // Add the decode signal to all views
                for (shared_ptr<views::ViewBase> view : views_)
                        view->add_decode_signal(signal);
-       } catch (runtime_error e) {
+       } catch (runtime_error& e) {
                remove_decode_signal(signal);
                return nullptr;
        }
@@ -934,7 +934,7 @@ void Session::sample_thread_proc(function<void (const QString)> error_handler)
 
        try {
                device_->start();
-       } catch (Error e) {
+       } catch (Error& e) {
                error_handler(e.what());
                return;
        }
@@ -944,7 +944,7 @@ void Session::sample_thread_proc(function<void (const QString)> error_handler)
 
        try {
                device_->run();
-       } catch (Error e) {
+       } catch (Error& e) {
                error_handler(e.what());
                set_capture_state(Stopped);
                return;
@@ -1253,7 +1253,7 @@ void Session::data_feed_in(shared_ptr<sigrok::Device> device,
        case SR_DF_LOGIC:
                try {
                        feed_in_logic(dynamic_pointer_cast<Logic>(packet->payload()));
-               } catch (bad_alloc) {
+               } catch (bad_alloc&) {
                        out_of_memory_ = true;
                        device_->stop();
                }
@@ -1262,7 +1262,7 @@ void Session::data_feed_in(shared_ptr<sigrok::Device> device,
        case SR_DF_ANALOG:
                try {
                        feed_in_analog(dynamic_pointer_cast<Analog>(packet->payload()));
-               } catch (bad_alloc) {
+               } catch (bad_alloc&) {
                        out_of_memory_ = true;
                        device_->stop();
                }
index 494f2db3b91e7b8fe34ea1cfa56471f5ba4a8fc5..3d7b058a87034b6c02cc4109347e798b94702b40 100644 (file)
@@ -182,7 +182,7 @@ bool StoreSession::start()
                        {{ConfigKey::SAMPLERATE, Glib::Variant<guint64>::create(
                                any_segment->samplerate())}});
                output_->receive(meta);
-       } catch (Error error) {
+       } catch (Error& error) {
                error_ = tr("Error while saving: ") + error.what();
                return false;
        }
@@ -276,7 +276,7 @@ void StoreSession::store_proc(vector< shared_ptr<data::SignalBase> > achannel_li
 
                                delete[] ldata;
                        }
-               } catch (Error error) {
+               } catch (Error& error) {
                        error_ = tr("Error while saving: ") + error.what();
                        break;
                }
index b96bfbe78837325bed9c52b4eb86f35f23411a29..1797e0a43e7de836b3695cfde24cf09647b6d150 100644 (file)
@@ -305,7 +305,7 @@ void MainBar::update_sample_rate_selector()
        if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
                try {
                        gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
-               } catch (Error error) {
+               } catch (Error& error) {
                        qDebug() << tr("Failed to get sample rate list:") << error.what();
                }
        } else {
@@ -368,7 +368,7 @@ void MainBar::update_sample_rate_selector_value()
                updating_sample_rate_ = true;
                sample_rate_.set_value(samplerate);
                updating_sample_rate_ = false;
-       } catch (Error error) {
+       } catch (Error& error) {
                qDebug() << tr("Failed to get value of sample rate:") << error.what();
        }
 }
@@ -409,7 +409,7 @@ void MainBar::update_sample_count_selector()
                        if (gvar.gobj())
                                g_variant_get(gvar.gobj(), "(tt)",
                                        &min_sample_count, &max_sample_count);
-               } catch (Error error) {
+               } catch (Error& error) {
                        qDebug() << tr("Failed to get sample limit list:") << error.what();
                }
        }
@@ -501,7 +501,7 @@ void MainBar::commit_sample_rate()
                sr_dev->config_set(ConfigKey::SAMPLERATE,
                        Glib::Variant<guint64>::create(sample_rate));
                update_sample_rate_selector();
-       } catch (Error error) {
+       } catch (Error& error) {
                qDebug() << tr("Failed to configure samplerate:") << error.what();
                return;
        }
@@ -528,7 +528,7 @@ void MainBar::commit_sample_count()
                        sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
                                Glib::Variant<guint64>::create(sample_count));
                        update_sample_count_selector();
-               } catch (Error error) {
+               } catch (Error& error) {
                        qDebug() << tr("Failed to configure sample count:") << error.what();
                        return;
                }
index cb8e4a527938bde2dd056d2c563d61e6661fa579..3595840ecfebbf211df9c1cc5d67155329f5a65a 100644 (file)
@@ -669,7 +669,7 @@ shared_ptr<pv::data::AnalogSegment> AnalogSignal::get_analog_segment_to_paint()
                                (segment_display_mode_ == ShowLastCompleteSegmentOnly)) {
                        try {
                                segment = segments.at(current_segment_);
-                       } catch (out_of_range) {
+                       } catch (out_of_range&) {
                                qDebug() << "Current analog segment out of range for signal" << base_->name() << ":" << current_segment_;
                        }
                }
@@ -693,7 +693,7 @@ shared_ptr<pv::data::LogicSegment> AnalogSignal::get_logic_segment_to_paint() co
                                (segment_display_mode_ == ShowLastCompleteSegmentOnly)) {
                        try {
                                segment = segments.at(current_segment_);
-                       } catch (out_of_range) {
+                       } catch (out_of_range&) {
                                qDebug() << "Current logic segment out of range for signal" << base_->name() << ":" << current_segment_;
                        }
                }
index 88fa97fbc0b6f36cee3083892be919ba24260e09..bf31a72ac05adaee19ee78e6d54b1c9f3bc09191 100644 (file)
@@ -220,7 +220,7 @@ void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
                int row_title_width;
                try {
                        row_title_width = row_title_widths_.at(row);
-               } catch (out_of_range) {
+               } catch (out_of_range&) {
                        const int w = p.boundingRect(QRectF(), 0, row.title()).width() +
                                RowTitleMargin;
                        row_title_widths_[row] = w;
index 1f25890dd5b7a3e11f83afd909a053e1d79c8990..759f85881c1ed7ba9afb0b6ad1a2b1003063d1df 100644 (file)
@@ -362,7 +362,7 @@ shared_ptr<pv::data::LogicSegment> LogicSignal::get_logic_segment_to_paint() con
                (segment_display_mode_ == ShowLastCompleteSegmentOnly)) {
                        try {
                                segment = segments.at(current_segment_);
-                       } catch (out_of_range) {
+                       } catch (out_of_range&) {
                                qDebug() << "Current logic segment out of range for signal" << base_->name() << ":" << current_segment_;
                        }
                }