microsoft / microsoft/wil

Condider migrating to `std::source_location`

Open
#186 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3k
Forks
300
Avg merge
19h 12m
Merged PRs (30d)
1

Description

Macro's like THROW_IF_WIN32_BOOL_FALSE(b) are painful to use. They have long names, but shorter names could easily clash with other names. I'd much rather do something like using namespace wil::throwing; win32Bool(b). With C++ 20's std::source_location implemented in the latest MSVC version this is now possible.

Additionally, it allows to change the position included in the message. For example:

void throwIfUnexpected(DWORD win32) {
    if (win32 != ERROR_ALREADY_EXISTS) THROW_WIN32(win32);
}

void createFile() {
    if (!CreateFile(... CREATE_ALWAYS ...)) throwIfUnexpected(GetLastError());
}

This will report an error in throwIfUnexpected, but if this function is reused often it would be much more helpful to report the error in the createFile function.

With source_location this would be possible:

void throwIfUnexpected(DWORD win32, std::source_location loc = std::source_location::current()) {
    if (win32 != ERROR_ALREADY_EXISTS) wil::throwWin32(win32, loc); //or something
}

The only downsides are that we cannot get the return address or evaluated expression from source_location. (In C++ 23, the former can be replaced with by using std::stacktrace_entry.)

Very much related: microsoft/cppwinrt#761

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the THROW_IF_WIN32_BOOL_FALSE macro, THROW_WIN32, wil::throwWin32, and the proposed std::source_location usage in the issue. Compare the tradeoffs with microsoft/cppwinrt#761; done would require an agreed migration design that addresses source locations, return addresses, and evaluated expressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.