From 3e7d0222b7b5eb096d926b08deb4bdf63a4a7b3c Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Sat, 7 Jan 2023 15:29:24 +0100 Subject: [PATCH] Makes the PWM interface compatible with constexpr. (#690) Similar to GPIO classes, we often have many PWM objects allocated for multi-channel output use-cases. By making PWM interface compatible with constexpr, we allow for implementations to build these definitions into read-only memory (flash), reducing the RAM footprint of a multi-channel PWM device. There are specific requirementsfor making a class constexpr in C++11, and the base classes have to comply with them as well. This PR makes the PWM base class comply with these requirements. --- src/freertos_drivers/common/PWM.hxx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/freertos_drivers/common/PWM.hxx b/src/freertos_drivers/common/PWM.hxx index 2a50bb60d..9e073da53 100644 --- a/src/freertos_drivers/common/PWM.hxx +++ b/src/freertos_drivers/common/PWM.hxx @@ -83,15 +83,14 @@ public: protected: /// Constructor. - PWM() - { - } - - /// Destructor. - ~PWM() - { - } - + constexpr PWM() = default; + + /// Destructor. This is protected, because only child classes should be + /// allowed to destruct a PWM; but no implementation exists in order to + /// make the the destructor trivial for C++. A trivial destructor is + /// required for a constexpr class. + ~PWM() = default; + private: DISALLOW_COPY_AND_ASSIGN(PWM);