clang-tidy: bugprone-virtual-near-miss

A few virtual functions are called by constructors or destructors, which is
dangerous in C++ (as an overridden virtual impl won't be called, only the
one in the current class).  Fix by either marking the function final or
not calling at all (if possible).
This commit is contained in:
Peter Johnson
2020-12-26 22:06:28 -08:00
parent cbe59fa3bf
commit b60eb1544b
22 changed files with 14 additions and 25 deletions

View File

@@ -23,7 +23,6 @@ NTCommandSchedulerModel::NTCommandSchedulerModel(NT_Inst instance,
m_nt.AddListener(m_commands);
m_nt.AddListener(m_ids);
m_nt.AddListener(m_cancel);
Update();
}
void NTCommandSchedulerModel::CancelCommand(size_t index) {

View File

@@ -19,7 +19,6 @@ NTCommandSelectorModel::NTCommandSelectorModel(NT_Inst instance,
m_runningData.SetDigital(true);
m_nt.AddListener(m_running);
m_nt.AddListener(m_name);
Update();
}
void NTCommandSelectorModel::SetRunning(bool run) {

View File

@@ -21,7 +21,6 @@ NTDigitalInputModel::NTDigitalInputModel(NT_Inst inst, wpi::StringRef path)
m_nt.AddListener(m_name);
m_valueData.SetDigital(true);
Update();
}
void NTDigitalInputModel::Update() {

View File

@@ -22,7 +22,6 @@ NTDigitalOutputModel::NTDigitalOutputModel(NT_Inst inst, wpi::StringRef path)
m_nt.AddListener(m_controllable);
m_valueData.SetDigital(true);
Update();
}
void NTDigitalOutputModel::SetValue(bool val) {

View File

@@ -37,7 +37,6 @@ NTFMSModel::NTFMSModel(NT_Inst inst, wpi::StringRef path)
m_enabled.SetDigital(true);
m_test.SetDigital(true);
m_autonomous.SetDigital(true);
Update();
}
wpi::StringRef NTFMSModel::GetGameSpecificMessage(

View File

@@ -147,7 +147,7 @@ void NTField2DModel::GroupModel::ObjectModel::SetPoseImpl(double x, double y,
return;
}
auto origArr = value->GetDoubleArray();
if (origArr.size() < static_cast<size_t>((m_index + 1) * 3)) {
if (static_cast<int>(origArr.size()) < ((m_index + 1) * 3)) {
return;
}

View File

@@ -17,7 +17,6 @@ NTGyroModel::NTGyroModel(NT_Inst instance, wpi::StringRef path)
m_nameValue(path.rsplit('/').second) {
m_nt.AddListener(m_angle);
m_nt.AddListener(m_name);
Update();
}
void NTGyroModel::Update() {

View File

@@ -27,7 +27,6 @@ NTPIDControllerModel::NTPIDControllerModel(NT_Inst instance,
m_nt.AddListener(m_i);
m_nt.AddListener(m_d);
m_nt.AddListener(m_setpoint);
Update();
}
void NTPIDControllerModel::SetP(double value) {

View File

@@ -18,7 +18,6 @@ NTSpeedControllerModel::NTSpeedControllerModel(NT_Inst instance,
m_nameValue(path.rsplit('/').second) {
m_nt.AddListener(m_value);
m_nt.AddListener(m_name);
Update();
}
void NTSpeedControllerModel::SetPercent(double value) {

View File

@@ -19,8 +19,6 @@ NTStringChooserModel::NTStringChooserModel(NT_Inst inst, wpi::StringRef path)
m_nt.AddListener(m_selected);
m_nt.AddListener(m_active);
m_nt.AddListener(m_options);
Update();
}
void NTStringChooserModel::SetDefault(wpi::StringRef val) {

View File

@@ -17,7 +17,6 @@ NTSubsystemModel::NTSubsystemModel(NT_Inst instance, wpi::StringRef path)
m_nt.AddListener(m_name);
m_nt.AddListener(m_defaultCommand);
m_nt.AddListener(m_currentCommand);
Update();
}
void NTSubsystemModel::Update() {

View File

@@ -83,7 +83,7 @@ class ParallelCommandGroup
bool RunsWhenDisabled() const override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
bool m_runWhenDisabled{true};

View File

@@ -91,7 +91,7 @@ class ParallelDeadlineGroup
bool RunsWhenDisabled() const override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
void SetDeadline(std::unique_ptr<Command>&& deadline);

View File

@@ -71,7 +71,7 @@ class ParallelRaceGroup
bool RunsWhenDisabled() const override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
std::vector<std::unique_ptr<Command>> m_commands;
bool m_runWhenDisabled{true};

View File

@@ -51,7 +51,7 @@ class ADXL345_I2C : public ErrorBase,
ADXL345_I2C& operator=(ADXL345_I2C&&) = default;
// Accelerometer interface
void SetRange(Range range) override;
void SetRange(Range range) final;
double GetX() override;
double GetY() override;
double GetZ() override;

View File

@@ -47,7 +47,7 @@ class ADXL345_SPI : public ErrorBase,
ADXL345_SPI& operator=(ADXL345_SPI&&) = default;
// Accelerometer interface
void SetRange(Range range) override;
void SetRange(Range range) final;
double GetX() override;
double GetY() override;
double GetZ() override;

View File

@@ -55,7 +55,7 @@ class ADXL362 : public ErrorBase,
ADXL362& operator=(ADXL362&&) = default;
// Accelerometer interface
void SetRange(Range range) override;
void SetRange(Range range) final;
double GetX() override;
double GetY() override;
double GetZ() override;

View File

@@ -87,7 +87,7 @@ class ADXRS450_Gyro : public GyroBase {
* robot is first turned on while it's sitting at rest before the competition
* starts.
*/
void Calibrate() override;
void Calibrate() final;
/**
* Get the SPI port number.

View File

@@ -172,16 +172,16 @@ class AnalogGyro : public GyroBase {
* significant drift in the gyro and it needs to be recalibrated after it has
* been running.
*/
void Reset() override;
void Reset() final;
/**
* Initialize the gyro.
*
* Calibration is handled by Calibrate().
*/
virtual void InitGyro();
void InitGyro();
void Calibrate() override;
void Calibrate() final;
/**
* Gets the analog input for the gyro.

View File

@@ -45,7 +45,7 @@ class SimDeviceSim {
});
}
operator HAL_SimDeviceHandle() const { return m_handle; }
operator HAL_SimDeviceHandle() const { return m_handle; } // NOLINT
template <typename F>
static void EnumerateDevices(const char* prefix, F callback) {

View File

@@ -48,7 +48,7 @@ class TCPAcceptor : public NetworkAcceptor {
~TCPAcceptor() override;
int start() override;
void shutdown() override;
void shutdown() final;
std::unique_ptr<NetworkStream> accept() override;
};

View File

@@ -158,7 +158,7 @@ class raw_fd_istream : public raw_istream {
size_t bufSize = 4096);
raw_fd_istream(int fd, bool shouldClose, size_t bufSize = 4096);
~raw_fd_istream() override;
void close() override;
void close() final;
size_t in_avail() const override;
private: