Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devirtualize destructors #37708

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ config("strict_warnings") {
cflags -= [ "-Wshadow" ]
}

cflags_cc = [ "-Wnon-virtual-dtor" ]
cflags_cc = [ "-Wdelete-non-virtual-dtor" ]

if (current_os == "nuttx") {
cflags -= [ "-Wshadow" ]
cflags_cc -= [ "-Wnon-virtual-dtor" ]
cflags_cc -= [ "-Wdelete-non-virtual-dtor" ]
}

configs = []
Expand Down
21 changes: 11 additions & 10 deletions src/access/AccessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class AccessControl
struct DeviceTypeResolver
{
public:
virtual ~DeviceTypeResolver() = default;

virtual bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint) = 0;

protected:
~DeviceTypeResolver() = default;
};

/**
Expand All @@ -76,12 +77,11 @@ class AccessControl
{
public:
Delegate() = default;
virtual ~Delegate() = default;

Delegate(const Delegate &) = delete;
Delegate & operator=(const Delegate &) = delete;

virtual ~Delegate() = default;

virtual void Release() {}

// Simple getters
Expand Down Expand Up @@ -250,12 +250,11 @@ class AccessControl
{
public:
Delegate() = default;
virtual ~Delegate() = default;

Delegate(const Delegate &) = delete;
Delegate & operator=(const Delegate &) = delete;

virtual ~Delegate() = default;

virtual void Release() {}

virtual CHIP_ERROR Next(Entry & entry) { return CHIP_ERROR_SENTINEL; }
Expand Down Expand Up @@ -304,8 +303,6 @@ class AccessControl
kUpdated = 3
};

virtual ~EntryListener() = default;

/**
* Notifies of a change in the access control list.
*
Expand All @@ -322,6 +319,9 @@ class AccessControl
virtual void OnEntryChanged(const SubjectDescriptor * subjectDescriptor, FabricIndex fabric, size_t index,
const Entry * entry, ChangeType changeType) = 0;

protected:
~EntryListener() = default;

private:
EntryListener * mNext = nullptr;

Expand All @@ -336,8 +336,6 @@ class AccessControl
Delegate(const Delegate &) = delete;
Delegate & operator=(const Delegate &) = delete;

virtual ~Delegate() = default;

virtual void Release() {}

virtual CHIP_ERROR Init() { return CHIP_NO_ERROR; }
Expand Down Expand Up @@ -402,6 +400,9 @@ class AccessControl
{
return CHIP_ERROR_ACCESS_DENIED;
}

protected:
~Delegate() = default;
};

AccessControl() = default;
Expand Down
4 changes: 3 additions & 1 deletion src/credentials/GroupDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class GroupDataProvider
class GroupListener
{
public:
virtual ~GroupListener() = default;
/**
* Callback invoked when a new group is added.
*
Expand All @@ -185,6 +184,9 @@ class GroupDataProvider
* @param[in] old_group GroupInfo structure of the removed group.
*/
virtual void OnGroupRemoved(FabricIndex fabric_index, const GroupInfo & old_group) = 0;

protected:
~GroupListener() = default;
};

using GroupInfoIterator = CommonIterator<GroupInfo>;
Expand Down
5 changes: 3 additions & 2 deletions src/crypto/OperationalKeystore.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace Crypto {
class OperationalKeystore
{
public:
virtual ~OperationalKeystore() {}

// ==== API designed for commisionables to support fail-safe (although can be used by controllers) ====

/**
Expand Down Expand Up @@ -246,6 +244,9 @@ class OperationalKeystore
* @brief Release an ephemeral keypair previously provided by `AllocateEphemeralKeypairForCASE()`
*/
virtual void ReleaseEphemeralKeypair(Crypto::P256Keypair * keypair) = 0;

protected:
~OperationalKeystore() = default;
Comment on lines +248 to +249
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one NEEDS to remain virtual as it is widely deployed by ecosystems with non-default operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that ecosystems destroy this object using the base pointer?

};

} // namespace Crypto
Expand Down
6 changes: 4 additions & 2 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ class ConfigurationManager
virtual CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) = 0;

// Construction/destruction limited to subclasses.
ConfigurationManager() = default;
virtual ~ConfigurationManager() = default;
ConfigurationManager() = default;

// No copy, move or assignment.
ConfigurationManager(const ConfigurationManager &) = delete;
ConfigurationManager(const ConfigurationManager &&) = delete;
ConfigurationManager & operator=(const ConfigurationManager &) = delete;

protected:
~ConfigurationManager() = default;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions src/include/platform/ConnectivityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ class ConnectivityManagerImpl;
class ConnectivityManagerDelegate
{
public:
virtual ~ConnectivityManagerDelegate() {}

/**
* @brief
* Called when any network interface on the Node is changed
*
*/
virtual void OnNetworkInfoChanged() {}

protected:
~ConnectivityManagerDelegate() {}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/include/platform/DeviceInfoProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class DeviceInfoProvider
class Iterator
{
public:
virtual ~Iterator() = default;
/**
* @retval The number of entries in total that will be iterated.
*/
Expand All @@ -63,6 +62,7 @@ class DeviceInfoProvider

protected:
Iterator() = default;
~Iterator() = default;
};

using FixedLabelType = app::Clusters::FixedLabel::Structs::LabelStruct::Type;
Expand Down
10 changes: 6 additions & 4 deletions src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class DiagnosticDataProviderImpl;
class WiFiDiagnosticsDelegate
{
public:
virtual ~WiFiDiagnosticsDelegate() {}

/**
* @brief
* Called when the Node detects Node’s Wi-Fi connection has been disconnected.
Expand All @@ -88,6 +86,9 @@ class WiFiDiagnosticsDelegate
* Called when the Node’s connection status to a Wi-Fi network has changed.
*/
virtual void OnConnectionStatusChanged(uint8_t connectionStatus) {}

protected:
~WiFiDiagnosticsDelegate() = default;
};

/**
Expand All @@ -96,8 +97,6 @@ class WiFiDiagnosticsDelegate
class ThreadDiagnosticsDelegate
{
public:
virtual ~ThreadDiagnosticsDelegate() {}

/**
* @brief
* Called when the Node’s connection status to a Thread network has changed.
Expand All @@ -111,6 +110,9 @@ class ThreadDiagnosticsDelegate
virtual void OnNetworkFaultChanged(const GeneralFaults<kMaxNetworkFaults> & previous,
const GeneralFaults<kMaxNetworkFaults> & current)
{}

protected:
~ThreadDiagnosticsDelegate() {}
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
#endif
void LogDeviceConfig() override;

~GenericConfigurationManagerImpl() override = default;

protected:
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
chip::LifetimePersistedCounter<uint32_t> mLifetimePersistedCounter;
Expand Down
Loading