Fix or suppress clang-tidy warnings (#8254)

This commit is contained in:
Tyler Veness
2025-09-25 21:28:04 -07:00
committed by GitHub
parent 5003939b64
commit ab53d51c6f
28 changed files with 62 additions and 56 deletions

View File

@@ -45,6 +45,8 @@ Checks:
-clang-diagnostic-#warnings,
-clang-diagnostic-pedantic,
clang-analyzer-*,
-clang-analyzer-optin.cplusplus.UninitializedObject,
-clang-analyzer-security.FloatLoopCounter,
cppcoreguidelines-slicing,
google-build-namespaces,
google-explicit-constructor,

View File

@@ -22,6 +22,7 @@ void BM_Transform(benchmark::State& state) {
auto transform = pose2 - pose1;
return units::math::hypot(transform.X(), transform.Y()).value();
}};
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
for (auto _ : state) {
traveler.Solve(poses, iterations);
}
@@ -33,6 +34,7 @@ void BM_Twist(benchmark::State& state) {
auto twist = pose1.Log(pose2);
return units::math::hypot(twist.dx, twist.dy).value();
}};
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
for (auto _ : state) {
traveler.Solve(poses, iterations);
}

View File

@@ -5,7 +5,6 @@
#include <opencv2/core/core.hpp>
#include <wpi/print.h>
#include "cscore.h"
#include "cscore_cv.h"
int main() {

View File

@@ -44,7 +44,7 @@ static O* ConvertToC(std::vector<I>&& in, int* count) {
// retain vector at end of returned array
alignas(T) unsigned char buf[sizeof(T)];
new (buf) T(std::move(in));
std::memcpy(out + size * sizeof(O), buf, sizeof(T));
std::memcpy(out + size, buf, sizeof(T));
return out;
}
@@ -392,7 +392,7 @@ void CS_FreeEvents(CS_Event* arr, int count) {
// destroy vector saved at end of array
using T = std::vector<cs::RawEvent>;
alignas(T) unsigned char buf[sizeof(T)];
std::memcpy(buf, arr + count * sizeof(CS_Event), sizeof(T));
std::memcpy(buf, arr + count, sizeof(T));
reinterpret_cast<T*>(buf)->~T();
std::free(arr);

View File

@@ -707,8 +707,9 @@ void UsbCameraImpl::DeviceCacheProperty(
}
NotifyPropertyCreated(*rawIndex, *rawPropPtr);
if (perPropPtr && perIndex)
if (perPropPtr && perIndex) {
NotifyPropertyCreated(*perIndex, *perPropPtr);
}
}
CS_StatusValue UsbCameraImpl::DeviceProcessCommand(

View File

@@ -4,11 +4,8 @@
#include "glass/other/PIDController.h"
#include <string>
#include <imgui.h>
#include "glass/Context.h"
#include "glass/DataSource.h"
using namespace glass;
@@ -34,8 +31,8 @@ void glass::DisplayPIDController(PIDControllerModel* m) {
[flag](const char* name, double* v,
std::function<void(double)> callback) {
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, NULL, NULL,
"%.3f", flag)) {
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, nullptr,
nullptr, "%.3f", flag)) {
callback(*v);
}
};

View File

@@ -4,11 +4,8 @@
#include "glass/other/ProfiledPIDController.h"
#include <string>
#include <imgui.h>
#include "glass/Context.h"
#include "glass/DataSource.h"
using namespace glass;
@@ -34,8 +31,8 @@ void glass::DisplayProfiledPIDController(ProfiledPIDControllerModel* m) {
[flag](const char* name, double* v,
std::function<void(double)> callback) {
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, NULL, NULL,
"%.3f", flag)) {
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, nullptr,
nullptr, "%.3f", flag)) {
callback(*v);
}
};

View File

@@ -44,6 +44,7 @@ Checks:
-clang-diagnostic-#warnings,
-clang-diagnostic-pedantic,
clang-analyzer-*,
-clang-analyzer-optin.cplusplus.UninitializedObject,
cppcoreguidelines-slicing,
google-build-namespaces,
google-explicit-constructor,

View File

@@ -11,20 +11,17 @@
int main() {
auto inst = nt::GetDefaultInstance();
nt::AddLogger(
inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::StartClient(inst, "127.0.0.1", 10000);
nt::AddLogger(inst, 0, UINT_MAX, [](const nt::Event& event) {
std::fputs(event.GetLogMessage()->message.c_str(), stderr);
std::fputc('\n', stderr);
});
nt::StartClient4(inst, "127.0.0.1");
std::this_thread::sleep_for(std::chrono::seconds(2));
auto foo = nt::GetEntry(inst, "/foo");
auto foo_val = nt::GetEntryValue(foo);
if (foo_val && foo_val->IsDouble()) {
std::printf("Got foo: %g\n", foo_val->GetDouble());
if (foo_val && foo_val.IsDouble()) {
std::printf("Got foo: %g\n", foo_val.GetDouble());
}
auto bar = nt::GetEntry(inst, "/bar");

View File

@@ -11,14 +11,11 @@
int main() {
auto inst = nt::GetDefaultInstance();
nt::AddLogger(
inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::StartServer(inst, "persistent.ini", "", 10000);
nt::AddLogger(inst, 0, UINT_MAX, [](const nt::Event& event) {
std::fputs(event.GetLogMessage()->message.c_str(), stderr);
std::fputc('\n', stderr);
});
nt::StartServer(inst, "persistent.ini", "", 10000, 10001);
std::this_thread::sleep_for(std::chrono::seconds(1));
auto foo = nt::GetEntry(inst, "/foo");

View File

@@ -177,6 +177,7 @@ static_assert(ValidType<uint8_t[]>);
static_assert(ValidType<std::vector<uint8_t>>);
template <ValidType T, NT_Type type>
// NOLINTNEXTLINE(google-readability-casting)
constexpr bool IsNTType = TypeInfo<std::remove_cvref_t<T>>::kType == type;
static_assert(IsNTType<bool, NT_BOOLEAN>);

View File

@@ -4,6 +4,8 @@
#pragma once
#include <stdint.h>
#include <functional>
#include <string_view>

View File

@@ -7,9 +7,7 @@
#include <stdint.h>
#include <atomic>
#include <concepts>
#include <span>
#include <string_view>
#include <utility>
#include <vector>
@@ -207,7 +205,7 @@ class ProtobufPublisher : public Publisher {
ProtobufPublisher(ProtobufPublisher&& rhs)
: Publisher{std::move(rhs)},
m_msg{std::move(rhs.m_msg)},
m_schemaPublished{rhs.m_schemaPublished} {}
m_schemaPublished{rhs.m_schemaPublished.load()} {}
ProtobufPublisher& operator=(ProtobufPublisher&& rhs) {
Publisher::operator=(std::move(rhs));

View File

@@ -157,7 +157,7 @@ namespace nt {
class StructTest : public ::testing::Test {
public:
StructTest() { inst = nt::NetworkTableInstance::Create(); }
~StructTest() { nt::NetworkTableInstance::Destroy(inst); }
~StructTest() override { nt::NetworkTableInstance::Destroy(inst); }
nt::NetworkTableInstance inst;
};

View File

@@ -72,8 +72,9 @@ int StartJavaTool(std::filesystem::path& exePath) {
std::string data = jarPath;
std::string jarArg = "-jar";
char* const arguments[] = {Java.generic_string().data(), jarArg.data(),
data.data(), nullptr};
auto javaGenericStr = Java.generic_string();
char* const arguments[] = {javaGenericStr.data(), jarArg.data(), data.data(),
nullptr};
int status =
posix_spawn(&pid, Java.c_str(), nullptr, nullptr, arguments, environ);

View File

@@ -69,10 +69,12 @@ TEST_F(DSCommPacketTest, MainJoystickTag) {
std::array<uint8_t, 12> _buttons{{0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1}};
std::array<uint8_t, 2> _button_bytes{{0, 0}};
for (int btn = 0; btn < 8; btn++)
for (int btn = 0; btn < 8; btn++) {
_button_bytes[1] |= _buttons[btn] << btn;
for (int btn = 8; btn < 12; btn++)
}
for (int btn = 8; btn < 12; btn++) {
_button_bytes[0] |= _buttons[btn] << (btn - 8);
}
// 5 for base, 4 joystick, 12 buttons (2 bytes) 3 povs
uint8_t arr[5 + 4 + 2 + 6] = {// Size, Tag

View File

@@ -31,7 +31,6 @@ includeOtherLibs {
^mrcal_wrapper\.h$
^opencv2\.h$
^portable-file-dialogs\.h$
^tagpose\.h$
^wpi/
^wpigui
}

View File

@@ -19,10 +19,11 @@
#include <fmt/format.h>
#include <imgui.h>
#include <portable-file-dialogs.h>
#include <tagpose.h>
#include <wpi/json.h>
#include <wpigui.h>
#include "tagpose.h"
namespace gui = wpi::gui;
const char* GetWPILibVersion();
@@ -140,7 +141,7 @@ static bool EmitEntryTarget(int tag_id, std::string& file) {
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* payload =
ImGui::AcceptDragDropPayload("FieldCalibration")) {
file = *(std::string*)payload->Data;
file = *static_cast<std::string*>(payload->Data);
rv = true;
}
ImGui::EndDragDropTarget();

View File

@@ -2,7 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <tagpose.h>
#include "tagpose.h"
#include <wpi/deprecated.h>
WPI_IGNORE_DEPRECATED

View File

@@ -7,9 +7,10 @@
#include <cmath>
#include <map>
#include <tagpose.h>
#include <wpi/json.h>
#include "tagpose.h"
class Fieldmap {
public:
Fieldmap() = default;

View File

@@ -4,11 +4,11 @@
#pragma once
#include <fieldmap.h>
#include <tagpose.h>
#include <wpi/json.h>
#include "fieldmap.h"
#include "tagpose.h"
namespace fmap {
wpi::json singleTag(int tag, const tag::Pose& tagpose);
wpi::json convertfmap(const wpi::json& json);

View File

@@ -53,7 +53,7 @@ class Config {
std::optional<units::volt_t> stepVoltage,
std::optional<units::second_t> timeout,
std::function<void(frc::sysid::State)> recordState)
: m_recordState{recordState} {
: m_recordState{std::move(recordState)} {
if (rampRate) {
m_rampRate = rampRate.value();
}

View File

@@ -79,9 +79,9 @@ ADIS16470_IMU::ADIS16470_IMU(IMUAxis yaw_axis, IMUAxis pitch_axis,
"IMUAxis.kZ as arguments.");
REPORT_ERROR(
"Constructing ADIS with default axes. (IMUAxis.kZ is defined as Yaw)");
yaw_axis = kZ;
pitch_axis = kY;
roll_axis = kX;
m_yaw_axis = kZ;
m_pitch_axis = kY;
m_roll_axis = kX;
}
if (m_simDevice) {

View File

@@ -22,7 +22,7 @@ using namespace frc;
using enum Alert::AlertType;
class AlertsTest : public ::testing::Test {
public:
~AlertsTest() {
~AlertsTest() override {
// test all destructors
Update();
EXPECT_EQ(GetSubscriberForType(kError).Get().size(), 0ul);

View File

@@ -4,14 +4,16 @@
#include "commands/TeleopArcadeDrive.h"
#include <utility>
#include "subsystems/Drivetrain.h"
TeleopArcadeDrive::TeleopArcadeDrive(
Drivetrain* subsystem, std::function<double()> xaxisSpeedSupplier,
std::function<double()> zaxisRotateSuppplier)
: m_drive{subsystem},
m_xaxisSpeedSupplier{xaxisSpeedSupplier},
m_zaxisRotateSupplier{zaxisRotateSuppplier} {
m_xaxisSpeedSupplier{std::move(xaxisSpeedSupplier)},
m_zaxisRotateSupplier{std::move(zaxisRotateSuppplier)} {
AddRequirements(subsystem);
}

View File

@@ -171,8 +171,9 @@ TEST_F(DIOLoopTest, SynchronousInterruptWorks) {
timer.Start();
interrupt.WaitForInterrupt(kSynchronousInterruptTime + 1_s);
auto time = timer.Get().value();
if (thr.joinable())
if (thr.joinable()) {
thr.join();
}
EXPECT_NEAR(kSynchronousInterruptTime.value(), time,
kSynchronousInterruptTimeTolerance.value());
}

View File

@@ -322,6 +322,7 @@ class JSpanBase {
}
}
// NOLINTNEXTLINE(google-explicit-constructor)
operator std::span<T, Size>() const { return array(); }
std::span<T, Size> array() const {

View File

@@ -335,6 +335,7 @@ TEST_F(StringMapTest, MoveConstruct) {
StringMap<int> A;
A["x"] = 42;
StringMap<int> B = std::move(A);
// NOLINTNEXTLINE(clang-analyzer-cplusplus.Move)
ASSERT_EQ(A.size(), 0u);
ASSERT_EQ(B.size(), 1u);
ASSERT_EQ(B["x"], 42);
@@ -348,8 +349,10 @@ TEST_F(StringMapTest, MoveAssignment) {
B["y"] = 117;
A = std::move(B);
ASSERT_EQ(A.size(), 1u);
// NOLINTNEXTLINE(clang-analyzer-cplusplus.Move)
ASSERT_EQ(B.size(), 0u);
ASSERT_EQ(A["y"], 117);
// NOLINTNEXTLINE(clang-analyzer-cplusplus.Move)
ASSERT_EQ(B.count("x"), 0u);
}