8000 Stop importing operator* and operator-> into Nullable. by bzbarsky-apple · Pull Request #34353 · project-chip/connectedhomeip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Stop importing operator* and operator-> into Nullable. #34353

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

Merged
Merged
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
10000
Diff view
6 changes: 3 additions & 3 deletions src/app/cluster-building-blocks/QuieterReporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class QuieterReportingAttribute
bool isChangeOfNull = newValue.IsNull() ^ mValue.IsNull();
bool areBothValuesNonNull = !newValue.IsNull() && !mValue.IsNull();

bool changeToFromZero = areBothValuesNonNull && (*newValue == 0 || *mValue == 0);
bool isIncrement = areBothValuesNonNull && (*newValue > *mValue);
bool isDecrement = areBothValuesNonNull && (*newValue < *mValue);
bool changeToFromZero = areBothValuesNonNull && (newValue.Value() == 0 || mValue.Value() == 0);
bool isIncrement = areBothValuesNonNull && (newValue.Value() > mValue.Value());
bool isDecrement = areBothValuesNonNull && (newValue.Value() < mValue.Value());

bool isNewlyDirty = isChangeOfNull;
isNewlyDirty =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TEST(TestQuieterReporting, ChangeOnIncrementPolicyWorks)
QuieterReportingAttribute<int> attribute{ MakeNullable<int>(10) };

// Always start not dirty (because first sub priming always just read value anyway).
ASSERT_EQ(*attribute.value(), 10);
ASSERT_EQ(attribute.value().Value(), 10);

auto now = fakeClock.now();

Expand Down Expand Up @@ -149,7 +149,7 @@ TEST(TestQuieterReporting, ChangeOnDecrementPolicyWorks)
QuieterReportingAttribute<int> attribute{ MakeNullable<int>(9) };

// Always start not dirty (because first sub priming always just read value anyway).
ASSERT_EQ(*attribute.value(), 9);
ASSERT_EQ(attribute.value().Value(), 9);

auto now = fakeClock.now();

Expand Down Expand Up @@ -202,7 +202,7 @@ TEST(TestQuieterReporting, SufficientChangePredicateWorks)
QuieterReportingAttribute<int> attribute{ MakeNullable<int>(9) };

// Always start not dirty (because first sub priming always just read value anyway).
ASSERT_EQ(*attribute.value(), 9);
ASSERT_EQ(attribute.value().Value(), 9);

auto now = fakeClock.now();

Expand Down
4 changes: 2 additions & 2 deletions src/app/codegen-data-model/CodegenDataModel_Write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ CHIP_ERROR DecodeIntoEmberBuffer(AttributeValueDecoder & decoder, bool isNullabl
// Nullable<uint8_t>(0xFF) is not representable because 0xFF is the encoding of NULL in ember
// as well as odd-sized integers (e.g. full 32-bit value like 0x11223344 cannot be written
// to a 3-byte odd-sized integger).
VerifyOrReturnError(Traits::CanRepresentValue(isNullable, *workingValue), CHIP_ERROR_INVALID_ARGUMENT);
Traits::WorkingToStorage(*workingValue, storageValue);
VerifyOrReturnError(Traits::CanRepresentValue(isNullable, workingValue.Value()), CHIP_ERROR_INVALID_ARGUMENT);
Traits::WorkingToStorage(workingValue.Value(), storageValue);
}

VerifyOrReturnError(out.size() >= sizeof(storageValue), CHIP_ERROR_INVALID_ARGUMENT);
Expand Down
7 changes: 5 additions & 2 deletions src/app/data-model/Nullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ struct Nullable : protected std::optional<T>
// all constructors of the base class within this derived class.
//
using std::optional<T>::optional;
using std::optional<T>::operator*;
using std::optional<T>::operator->;

// Do NOT pull in optional::operator* or optional::operator->, because that
// leads people to write code that looks like it should work, and compiles,
// but does not do the right things with TLV encoding and decoding, when
// nullable data model objects are involved.

Nullable(NullOptionalType) : std::optional<T>(std::nullopt) {}

Expand Down
Loading
0