Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UiaBool conversion to bool is incorrect #57

Open
joemmett opened this issue Feb 18, 2021 · 2 comments
Open

UiaBool conversion to bool is incorrect #57

joemmett opened this issue Feb 18, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@joemmett
Copy link
Member

joemmett commented Feb 18, 2021

I'm a dev on the MSVC compiler team and discovered a problem with the implementation of UiaBool while attempting to fix an overload resolution bug in the compiler.

Here's a reduced sample based on a subset of UiaBool that illustrates the problem: https://godbolt.org/z/57nMx5

For the test of a UiaBool with an implicit conversion to bool MSVC currently (but incorrectly) calls UiaBool::operator bool(). All other compilers, and MSVC with my fix, instead call UiaTypeBase::operator LocalT*, which will always yield 'true' as it's returning the non-null address of the variant member.

The main problem here is that the operator bool() overload will be a worse conversion than the base LocalT* conversion if the UiaBool object is not const (it involves a qualification conversion for the implicit object parameter, while the LocalT* conversion does not). This is because operator bool() is declared const, but operator LocalT*() is not.

There is a fundamental ambiguity here where there are implicit conversion sequences to both bool and BOOL*. One potential fix for this would be to make UiaBool::operator BOOL*() explicit.

@beweedon beweedon added the bug Something isn't working label Feb 18, 2021
@beweedon
Copy link
Contributor

Thanks so much for bringing this to our attention! And thanks for the super clear minimal example!

We can probably address this within the next week or two (unless you want to open a PR 😄). Is the MSVC bug currently in public builds of the compiler, or was it regressed internally? Is two weeks a quick enough timeframe to implement our fix here before the MSVC fix make it to insider builds?

Thanks again!

@joemmett
Copy link
Member Author

There's definitely no rush here. I found the problem with internal testing so the fix is not yet even in our development branch. Since this can be a silent behavior change it's likely I'll only be able to make this fix under /permissive- so you won't see it yet until #2 is resolved, but I wanted to give you a heads up about the potential problem.

Since I'm not very familiar with this project I didn't submit a PR cause I don't really know what the best solution is or how breaking it would be to existing users to change the BOOL* conversion to be explicit. There are several options to fix this, but each with tradeoffs. I'm happy to discuss more if you run into any problems trying to find a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants