aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLane Kolbly <lane.kolbly@ni.com>2021-07-09 17:02:06 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2021-07-14 16:19:20 -0500
commitf47df4d1a83289043ef40469141aaa03d0c60d35 (patch)
treeba7a251348ebce47b2c1df44e40c8ffb200fc3a5
parent14ea574bb7e1a8e6dc1d8d8935cd527b2947009c (diff)
downloaduhd-f47df4d1a83289043ef40469141aaa03d0c60d35.tar.gz
uhd-f47df4d1a83289043ef40469141aaa03d0c60d35.tar.bz2
uhd-f47df4d1a83289043ef40469141aaa03d0c60d35.zip
host: Add static_assert to prevent meta_range_t(0,0)
meta_range_t(0,0) actually calls the iterator-based constructor for meta_range_t, which is almost certainly not the intended constructor for that call syntax. Therefore, we add a static_assert to prevent such usage, and fix all failing instances.
-rw-r--r--host/include/uhd/types/ranges.hpp9
-rw-r--r--host/lib/rfnoc/radio_control_impl.cpp4
-rw-r--r--host/lib/usrp/multi_usrp.cpp4
-rw-r--r--host/lib/usrp/multi_usrp_rfnoc.cpp4
-rw-r--r--host/lib/usrp/x300/x300_radio_control.cpp4
-rw-r--r--mpm/lib/mykonos/ad937x_ctrl.cpp2
6 files changed, 18 insertions, 9 deletions
diff --git a/host/include/uhd/types/ranges.hpp b/host/include/uhd/types/ranges.hpp
index 361b0e9d3..05aa0fa7c 100644
--- a/host/include/uhd/types/ranges.hpp
+++ b/host/include/uhd/types/ranges.hpp
@@ -9,6 +9,7 @@
#include <uhd/config.hpp>
#include <string>
+#include <type_traits>
#include <vector>
namespace uhd {
@@ -76,6 +77,14 @@ struct UHD_API meta_range_t : std::vector<range_t>
meta_range_t(InputIterator first, InputIterator last)
: std::vector<range_t>(first, last)
{ /* NOP */
+ // This is to avoid people accidentally doing silly things like:
+ // meta_range_t(0, 0)
+ // which probably was supposed to call meta_range_t(double, double, double)
+ // but actually calls this constructor.
+ static_assert(
+ !std::is_integral<typename std::decay<InputIterator>::type>::value,
+ "You can't pass integers to meta_range_t's constructor!"
+ );
}
/*!
diff --git a/host/lib/rfnoc/radio_control_impl.cpp b/host/lib/rfnoc/radio_control_impl.cpp
index 0a3eda277..70b17efb3 100644
--- a/host/lib/rfnoc/radio_control_impl.cpp
+++ b/host/lib/rfnoc/radio_control_impl.cpp
@@ -767,7 +767,7 @@ void radio_control_impl::set_tx_dc_offset(const std::complex<double>&, size_t)
uhd::meta_range_t radio_control_impl::get_tx_dc_offset_range(size_t) const
{
- return uhd::meta_range_t(0, 0);
+ return uhd::meta_range_t(0.0, 0.0);
}
void radio_control_impl::set_tx_iq_balance(const std::complex<double>&, size_t)
@@ -792,7 +792,7 @@ void radio_control_impl::set_rx_dc_offset(const std::complex<double>&, size_t)
uhd::meta_range_t radio_control_impl::get_rx_dc_offset_range(size_t) const
{
- return uhd::meta_range_t(0, 0);
+ return uhd::meta_range_t(0.0, 0.0);
}
void radio_control_impl::set_rx_iq_balance(const bool enb, size_t)
diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp
index 721b57ec9..89c4cbc26 100644
--- a/host/lib/usrp/multi_usrp.cpp
+++ b/host/lib/usrp/multi_usrp.cpp
@@ -1847,7 +1847,7 @@ public:
} else {
UHD_LOGGER_WARNING("MULTI_USRP")
<< "This device does not support querying the RX DC offset range.";
- return meta_range_t(0, 0);
+ return meta_range_t(0.0, 0.0);
}
}
@@ -2340,7 +2340,7 @@ public:
} else {
UHD_LOGGER_WARNING("MULTI_USRP")
<< "This device does not support querying the TX DC offset range.";
- return meta_range_t(0, 0);
+ return meta_range_t(0.0, 0.0);
}
}
diff --git a/host/lib/usrp/multi_usrp_rfnoc.cpp b/host/lib/usrp/multi_usrp_rfnoc.cpp
index bee19215c..d1d90ed4d 100644
--- a/host/lib/usrp/multi_usrp_rfnoc.cpp
+++ b/host/lib/usrp/multi_usrp_rfnoc.cpp
@@ -1209,7 +1209,7 @@ public:
rx_chain.radio->get_rx_frequency_range(rx_chain.block_chan);
freq_range_t dsp_range =
(rx_chain.ddc) ? rx_chain.ddc->get_frequency_range(rx_chain.block_chan)
- : meta_range_t(0, 0);
+ : meta_range_t(0.0, 0.0);
// Create lambdas to feed to tune_xx_subdev_and_dsp()
// Note: If there is no DDC present, register empty lambdas for the DSP functions
auto set_rf_freq = [rx_chain](double freq) {
@@ -1840,7 +1840,7 @@ public:
tx_chain.radio->get_tx_frequency_range(tx_chain.block_chan);
freq_range_t dsp_range =
(tx_chain.duc) ? tx_chain.duc->get_frequency_range(tx_chain.block_chan)
- : meta_range_t(0, 0);
+ : meta_range_t(0.0, 0.0);
// Create lambdas to feed to tune_xx_subdev_and_dsp()
// Note: If there is no DDC present, register empty lambdas for the DSP functions
auto set_rf_freq = [tx_chain](double freq) {
diff --git a/host/lib/usrp/x300/x300_radio_control.cpp b/host/lib/usrp/x300/x300_radio_control.cpp
index 73006a7c8..54f03fc6c 100644
--- a/host/lib/usrp/x300/x300_radio_control.cpp
+++ b/host/lib/usrp/x300/x300_radio_control.cpp
@@ -821,7 +821,7 @@ public:
} else {
RFNOC_LOG_WARNING(
"This device does not support querying the TX DC offset range.");
- return meta_range_t(0, 0);
+ return meta_range_t(0.0, 0.0);
}
}
@@ -864,7 +864,7 @@ public:
} else {
RFNOC_LOG_WARNING(
"This device does not support querying the rx DC offset range.");
- return meta_range_t(0, 0);
+ return meta_range_t(0.0, 0.0);
}
}
diff --git a/mpm/lib/mykonos/ad937x_ctrl.cpp b/mpm/lib/mykonos/ad937x_ctrl.cpp
index f4abae7a7..7cd5c1d98 100644
--- a/mpm/lib/mykonos/ad937x_ctrl.cpp
+++ b/mpm/lib/mykonos/ad937x_ctrl.cpp
@@ -129,7 +129,7 @@ uhd::meta_range_t ad937x_ctrl::get_rf_freq_range(void)
uhd::meta_range_t ad937x_ctrl::get_bw_filter_range(void)
{
// TODO: fix
- return uhd::meta_range_t(0, 1);
+ return uhd::meta_range_t(0.0, 1.0);
}
std::vector<double> ad937x_ctrl::get_clock_rates(void)