diff --git a/Makefile b/Makefile index a729a65d..1b1a255b 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ EXCLUDE_SRCDIRS+=$(SRCDIR)/tests C_STANDARD=gnu2x CXX_STANDARD=gnu++23 -WARNFLAGS+=-Wall -Wpedantic +WARNFLAGS+=-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Werror -Wno-error=deprecated-declarations EXTRA_CFLAGS+= EXTRA_CXXFLAGS=-D_PROS_KERNEL_SUPPRESS_LLEMU_WARNING diff --git a/azure-pipelines.yml b/azure-pipelines.yml index fbf415e9..41ab862d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,7 +29,7 @@ jobs: - bash: pip install pros-cli displayName: Install CLI - bash: | - make template + make template -k mkdir -p artifacts cp template/*.zip artifacts displayName: Build template diff --git a/include/common/cobs.h b/include/common/cobs.h index fe8c6a75..b772cc01 100644 --- a/include/common/cobs.h +++ b/include/common/cobs.h @@ -36,7 +36,7 @@ * * \return The number of bytes written */ -int cobs_encode(uint8_t* restrict dest, const uint8_t* restrict src, const size_t src_len, const uint32_t prefix); +size_t cobs_encode(uint8_t* restrict dest, const uint8_t* restrict src, const size_t src_len, const uint32_t prefix); /** * Same as cobs_encode() but doesn't write to an output buffer. Used to diff --git a/include/pros/llemu.hpp b/include/pros/llemu.hpp index 6e860176..25d892fa 100644 --- a/include/pros/llemu.hpp +++ b/include/pros/llemu.hpp @@ -50,6 +50,8 @@ namespace pros { #if defined(_PROS_KERNEL_SUPPRESS_LLEMU_WARNING) || defined(_PROS_INCLUDE_LIBLVGL_LLEMU_HPP) namespace lcd { #else +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" namespace [[deprecated("Without liblvgl, LLEMU functions will not display anything. To install liblvgl run \"pros c install liblvgl\" in the PROS terminal.")]] lcd { #endif #pragma GCC diagnostic push @@ -144,4 +146,8 @@ namespace [[deprecated("Without liblvgl, LLEMU functions will not display anythi } // namespace lcd } // namespace pros +#ifndef _PROS_INCLUDE_LIBLVGL_LLEMU_HPP +#pragma GCC diagnostic pop +#endif + #endif // _PROS_LLEMU_HPP_ diff --git a/include/pros/motors.hpp b/include/pros/motors.hpp index a0782bd2..43d1be63 100644 --- a/include/pros/motors.hpp +++ b/include/pros/motors.hpp @@ -74,7 +74,7 @@ class Motor : public AbstractMotor, public Device { Motor(const std::int8_t port, const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid, const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid); - Motor(const Device& device) : Motor(device.get_port()){}; + Motor(const Device& device) : Device(device.get_port(), DeviceType::motor) {}; /// \name Motor movement functions /// These functions allow programmers to make motors move diff --git a/include/pros/rotation.hpp b/include/pros/rotation.hpp index 1e6dda9d..dbd77fed 100644 --- a/include/pros/rotation.hpp +++ b/include/pros/rotation.hpp @@ -55,7 +55,7 @@ class Rotation : public Device { */ Rotation(const std::int8_t port); - Rotation(const Device& device) : Rotation(device.get_port()){}; + Rotation(const Device& device) : Device(device.get_port(), DeviceType::rotation) {}; /** diff --git a/include/vdml/port.h b/include/vdml/port.h index df93ba87..ea3ac7c9 100644 --- a/include/vdml/port.h +++ b/include/vdml/port.h @@ -22,8 +22,8 @@ #define get_ports(ports, smart_port, adi_port) \ { \ uint32_t uport = (uint32_t)ports; \ - smart_port = uport & SMART_PORT_MASK; \ - adi_port = uport >> SMART_PORT_BITS; \ + smart_port = (typeof(smart_port)) (uport & SMART_PORT_MASK); \ + adi_port = (typeof(adi_port)) (uport >> SMART_PORT_BITS); \ } static inline uint32_t merge_adi_ports(uint8_t smart_port, uint8_t adi_port) { diff --git a/include/vdml/vdml.h b/include/vdml/vdml.h index cb7248a7..9c3ca33f 100644 --- a/include/vdml/vdml.h +++ b/include/vdml/vdml.h @@ -25,13 +25,18 @@ extern "C" { #endif +// If a is unsigned, (typeof (a)) (-1) will be a really big positive value, and the +// entire comparison will become a >= a, to work around -Wtype-limits. Otherwise, +// the comparison will expand to a >= 0, as expected. +#define GTEQ_ZERO(a) ((a) >= __builtin_choose_expr( (typeof (a)) (-1) > 0, (a), 0)) + /** * Macro, returns true if the port is in range of user configurable ports, * false otherwise. */ -#define VALIDATE_PORT_NO(PORT) ((PORT) >= 0 && (PORT) < NUM_V5_PORTS) +#define VALIDATE_PORT_NO(PORT) (GTEQ_ZERO(PORT) && (PORT) < NUM_V5_PORTS) -#define VALIDATE_PORT_NO_INTERNAL(PORT) ((PORT) >= 0 && (PORT) < V5_MAX_DEVICE_PORTS) +#define VALIDATE_PORT_NO_INTERNAL(PORT) (GTEQ_ZERO(PORT) && (PORT) < V5_MAX_DEVICE_PORTS) /** * Macro that handles error checking, sanity checking, automatic registration, @@ -49,11 +54,11 @@ extern "C" { * The error code that return if error checking failed */ #define claim_port(port, device_type, error_code) \ - if (registry_validate_binding(port, device_type) != 0) { \ + if (registry_validate_binding((uint8_t) (port), device_type) != 0) { \ return error_code; \ } \ - v5_smart_device_s_t* device = registry_get_device(port); \ - if (!port_mutex_take(port)) { \ + v5_smart_device_s_t* device = registry_get_device((uint8_t) (port)); \ + if (!port_mutex_take((uint8_t) (port))) { \ errno = EACCES; \ return error_code; \ } @@ -111,7 +116,7 @@ int32_t claim_port_try(uint8_t port, v5_device_e_t type); * \return The rtn parameter */ #define return_port(port, rtn) \ - port_mutex_give(port); \ + port_mutex_give((uint8_t) (port)); \ return rtn; /** diff --git a/src/common/cobs.c b/src/common/cobs.c index 809b4c9f..9ef7c59a 100644 --- a/src/common/cobs.c +++ b/src/common/cobs.c @@ -55,7 +55,7 @@ size_t cobs_encode_measure(const uint8_t* restrict src, const size_t src_len, co return write_idx; } -int cobs_encode(uint8_t* restrict dest, const uint8_t* restrict src, const size_t src_len, const uint32_t prefix) { +size_t cobs_encode(uint8_t* restrict dest, const uint8_t* restrict src, const size_t src_len, const uint32_t prefix) { size_t read_idx = 0; size_t write_idx = 1; size_t code_idx = 0;