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

win32_helpers.h no longer compiles with WIL_SUPPRESS_EXCEPTIONS and C++20 #512

Open
sylveon opened this issue Mar 31, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@sylveon
Copy link
Contributor

sylveon commented Mar 31, 2025

Compile the following in C++20 mode:

#define WIL_SUPPRESS_EXCEPTIONS
#include <Windows.h>
#include <wil/win32_helpers.h>

int main()
{

}

Observe error:

Build started at 03:35...
1>------ Build started: Project: ConsoleApplication10, Configuration: Debug x64 ------
1>ConsoleApplication10.cpp
1>Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(213,21): error C2039: 'bit_cast': is not a member of 'std'
1>(compiling source file 'ConsoleApplication10.cpp')
1>    C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\new.h(24,19):
1>    see declaration of 'std'
1>Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(213,30): error C2062: type 'unsigned __int64' unexpected
1>(compiling source file 'ConsoleApplication10.cpp')
1>Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(210,34): error C3615: constexpr function 'wil::filetime::to_int64' cannot result in a constant expression
1>(compiling source file 'ConsoleApplication10.cpp')
1>    Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(210,34):
1>    failure was caused by control reaching the end of a constexpr function
1>Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(224,21): error C2039: 'bit_cast': is not a member of 'std'
1>(compiling source file 'ConsoleApplication10.cpp')
1>    C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\new.h(24,19):
1>    see declaration of 'std'
1>Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(224,30): error C2275: 'FILETIME': expected an expression instead of a type
1>(compiling source file 'ConsoleApplication10.cpp')
1>Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(221,38): error C3615: constexpr function 'wil::filetime::from_int64' cannot result in a constant expression
1>(compiling source file 'ConsoleApplication10.cpp')
1>    Z:\Throwaway\ConsoleApplication10\ConsoleApplication10\vcpkg_installed\x64-windows\x64-windows\include\wil\win32_helpers.h(221,38):
1>    failure was caused by control reaching the end of a constexpr function
1>Done building project "ConsoleApplication10.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 03:35 and took 00.784 seconds ==========

This seems to be caused by #490: inclusion of <bit> is now ultimately guarded by WIL_USE_STL, however further down the file, the feature check for __cpp_lib_bit_cast is done without checking WIL_USE_STL first. Should be easy to fix.

WIL_USE_STL seems to be automatically determined based on exception support, but the entire <bit> header is exception-free. Should we exclude exception-free usage of STL facilities from that WIL_USE_STL macro, or add something like WIL_USE_NOEXCEPT_STL to allow inclusion of exception-free STL bits? With the obvious fix (adding WIL_USE_STL to the feature checks), people who suppress exceptions are being pessimized (worse codegen, no constexpr filetime) for no valid reason.

@dunhor
Copy link
Member

dunhor commented Mar 31, 2025

however further down the file, the feature check for __cpp_lib_bit_cast is done without checking WIL_USE_STL first. Should be easy to fix

Correct, the use should also be guarded. This instance was missed

Should we exclude exception-free usage of STL facilities from that WIL_USE_STL macro, or add something like WIL_USE_NOEXCEPT_STL to allow inclusion of exception-free STL bits

I'd rather we not increase the complexity in this space. The default value of WIL_USE_STL is heuristically chosen, but can be overridden by the consumer. If you want to disable exceptions, but still use parts of the STL, compile with -DWIL_USE_STL=1. Uses of STL features that throw exceptions should still be guarded by WIL_ENABLE_EXCEPTIONS.

@dunhor dunhor added the bug Something isn't working label Mar 31, 2025
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