Skip to content

Commit 5869973

Browse files
authored
diagnose throw_hresult(success_code) better (#689)
1 parent 048c5c6 commit 5869973

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

strings/base_error.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ WINRT_EXPORT namespace winrt
183183
return *this;
184184
}
185185

186-
explicit hresult_error(hresult const code) noexcept : m_code(code)
186+
explicit hresult_error(hresult const code) noexcept : m_code(verify_error(code))
187187
{
188188
originate(code, nullptr);
189189
}
190190

191-
hresult_error(hresult const code, param::hstring const& message) noexcept : m_code(code)
191+
hresult_error(hresult const code, param::hstring const& message) noexcept : m_code(verify_error(code))
192192
{
193193
originate(code, get_abi(message));
194194
}
195195

196-
hresult_error(hresult const code, take_ownership_from_abi_t) noexcept : m_code(code)
196+
hresult_error(hresult const code, take_ownership_from_abi_t) noexcept : m_code(verify_error(code))
197197
{
198198
com_ptr<impl::IErrorInfo> info;
199199
WINRT_IMPL_GetErrorInfo(0, info.put_void());
@@ -306,6 +306,13 @@ WINRT_EXPORT namespace winrt
306306
WINRT_VERIFY(info.try_as(m_info));
307307
}
308308

309+
static hresult verify_error(hresult const code) noexcept
310+
{
311+
WINRT_ASSERT(code < 0);
312+
return code;
313+
}
314+
315+
309316
#ifdef __clang__
310317
#pragma clang diagnostic push
311318
#pragma clang diagnostic ignored "-Wunused-private-field"

0 commit comments

Comments
 (0)