From 3f7af60e794651445fc65509c94ad5e3b0e83dda Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Tue, 14 Jun 2022 10:28:53 -0400 Subject: [PATCH] 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 Commit-Queue: Herb Derby --- tests/UtilsTest.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp index b765d922a1..b9508c07ce 100644 --- a/tests/UtilsTest.cpp +++ b/tests/UtilsTest.cpp @@ -175,6 +175,10 @@ DEF_TEST(Utils, reporter) { test_autostarray(reporter); } +static bool test_function(SkSpan 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 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}))); } }