Respect the lifespan of initializer_list constants

initializer_list constants only have a scope until the next
sequence point.

Change-Id: I5c52310042fc4773a3ac0e5f9d23ae45bb7b1229
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/549574
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-06-14 10:28:53 -04:00 committed by SkCQ
parent 54ef59188b
commit 3f7af60e79

View File

@ -175,6 +175,10 @@ DEF_TEST(Utils, reporter) {
test_autostarray(reporter);
}
static bool test_function(SkSpan<const int> s) {
return s[0] == 1 && s[1] == 2 && s[2] == 3;
}
DEF_TEST(SkSpan, reporter) {
// Test constness preservation for SkMakeSpan.
{
@ -240,10 +244,7 @@ DEF_TEST(SkSpan, reporter) {
{
// Uses SkMakeSpan(std::initializer_list<T> il)
auto s= SkMakeSpan({1, 2, 3});
REPORTER_ASSERT(reporter, s[0] == 1);
REPORTER_ASSERT(reporter, s[1] == 2);
REPORTER_ASSERT(reporter, s[2] == 3);
REPORTER_ASSERT(reporter, test_function(SkMakeSpan({1, 2, 3})));
}
}