Skip to content

Commit

Permalink
[attribute storage] revert attempt to use constexpr to skip compiling…
Browse files Browse the repository at this point in the history
… code

Turns out that while this works well on current compilers, it does not with many embedded toolchains.

- idea was that an if testing an always false constexpr bool should
  skip *compiling* its body.

- we need that because that body refers to a struct field that is non-existing
  in the case when the if condition is constexpr false

- note that we can't use a real >=C++17 constexpr if, because in the
  CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT>0 case, the condition cannot be a constexpr

Bottom line: there seems no way around the uglier #ifdef-in-middle-of-condition.
  • Loading branch information
plan44 committed Oct 25, 2024
1 parent dff279f commit e842241
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,6 @@ Status emAfReadOrWriteAttribute(const EmberAfAttributeSearchRecord * attRecord,
// Endpoint processing starts here, so reset the offset.
attributeStorageOffset = 0;
}
#else
constexpr bool hasDynamicAttributeStorage = false;
#endif

for (clusterIndex = 0; clusterIndex < endpointType->clusterCount; clusterIndex++)
Expand Down Expand Up @@ -736,10 +734,12 @@ Status emAfReadOrWriteAttribute(const EmberAfAttributeSearchRecord * attRecord,
{
attributeLocation = singletonAttributeLocation(am);
}
#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
else if (hasDynamicAttributeStorage)
{
attributeLocation = emAfEndpoints[ep].dynamicAttributeStorage.data();
}
#endif
else
{
attributeLocation = attributeData;
Expand Down Expand Up @@ -784,7 +784,11 @@ Status emAfReadOrWriteAttribute(const EmberAfAttributeSearchRecord * attRecord,

// Internal storage is only supported for fixed endpoints
// and dynamic ones with dynamicAttributeStorage assigned.
if (!isDynamicEndpoint || hasDynamicAttributeStorage)
if (!isDynamicEndpoint
#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
|| hasDynamicAttributeStorage
#endif
)
{
return typeSensitiveMemCopy(attRecord->clusterId, dst, src, am, write, readLength);
}
Expand Down

0 comments on commit e842241

Please sign in to comment.