From af093723caaa204695b77b90c0d83474f9a6766e Mon Sep 17 00:00:00 2001 From: Duncan Horn <40036384+dunhor@users.noreply.github.com> Date: Thu, 23 Jan 2020 16:09:48 -0800 Subject: [PATCH] Fix unreachable warning (#112) --- tests/wiTest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/wiTest.cpp b/tests/wiTest.cpp index c422fbb91..4b23b5999 100644 --- a/tests/wiTest.cpp +++ b/tests/wiTest.cpp @@ -2494,7 +2494,8 @@ TEST_CASE("WindowsInternalTests::InitOnceNonTests") init = {}; // A thrown exception leaves the object un-initialized - REQUIRE_THROWS_AS(winner = wil::init_once(init, [&] { called = true; throw wil::ResultException(E_FAIL); }), wil::ResultException); + static volatile bool always_true = true; // So that the compiler can't determine that we unconditionally throw below (warning C4702) + REQUIRE_THROWS_AS(winner = wil::init_once(init, [&] { called = true; THROW_HR_IF(E_FAIL, always_true); }), wil::ResultException); REQUIRE_FALSE(wil::init_once_initialized(init)); REQUIRE(called); REQUIRE_FALSE(winner);