diff options
| author | akhropov <[email protected]> | 2025-10-17 11:43:35 +0300 |
|---|---|---|
| committer | akhropov <[email protected]> | 2025-10-17 12:38:17 +0300 |
| commit | 323f7e5f997c321f5970eb64578762834ca28ca4 (patch) | |
| tree | 7cb39416509a76096544a493a613a501e3d9caf4 /util/generic/array_ref_ut.cpp | |
| parent | 4f120e22def0ecbca49961cf9c8571bf0c8f5de5 (diff) | |
Check element size for other TArrayRef constructors, not only from Container
commit_hash:a53c0e1509e346d4e39464430ba21c3595315734
Diffstat (limited to 'util/generic/array_ref_ut.cpp')
| -rw-r--r-- | util/generic/array_ref_ut.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/util/generic/array_ref_ut.cpp b/util/generic/array_ref_ut.cpp index 67b1cf423ff..cebf4968889 100644 --- a/util/generic/array_ref_ut.cpp +++ b/util/generic/array_ref_ut.cpp @@ -24,6 +24,46 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { UNIT_ASSERT_VALUES_EQUAL(constRef[0], 100); } + // The following commented code should cause compilation errors + /* + struct TBase { + int X; + }; + + struct TDerived : public TBase { + int Y; + }; + + Y_UNIT_TEST(TestConstructorFromPtrSizeNonCompile) { + TDerived x[] = {{{10}, 1}, {{20}, 2}, {{30}, 3}}; + TArrayRef<TBase> ref(x, 3); + + TArrayRef<const TBase> constRef(x, 3); + } + + Y_UNIT_TEST(TestConstructorFromPtrsNonCompile) { + TDerived x[] = {{{10}, 1}, {{20}, 2}, {{30}, 3}}; + TArrayRef<TBase> ref(std::begin(x), std::end(x)); + + TArrayRef<const TBase> constRef(std::begin(x), std::end(x)); + } + + + Y_UNIT_TEST(TestConstructorFromUnrelatedPtrSizeNonCompile) { + float x[] = {10.0f, 20.0f, 30.0f}; + TArrayRef<i32> ref(x, std::size(x)); + + TArrayRef<const i32> constRef(x, std::size(x)); + } + + Y_UNIT_TEST(TestConstructorFromUnrelatedPtrsNonCompile) { + float x[] = {10.0f, 20.0f, 30.0f}; + TArrayRef<i32> ref(std::begin(x), std::end(x)); + + TArrayRef<const i32> constRef(std::begin(x), std::end(x)); + } + */ + Y_UNIT_TEST(TestAccessingElements) { int a[]{1, 2, 3}; TArrayRef<int> ref(a); |
