8000 Use the '-Xclang -fexceptions -Xclang -fcxx-exceptions' flag set to enables C++ EH in clang-cl · Issue #90 · qcoro/qcoro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use the '-Xclang -fexceptions -Xclang -fcxx-exceptions' flag set to enables C++ EH in clang-cl #90

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

Closed
missdeer opened this issue Jul 8, 2022 8000 · 5 comments
Labels
bug Something isn't working windows Windows/MSVC-specific issues

Comments

@missdeer
Copy link
missdeer commented Jul 8, 2022

With the latest clang-cl, it reports errors like below:

qcoro\qcorotask.h(615,13): error: cannot use 'try' with exceptions disabled

If C++ EH is enabled, errors disappeared.

@danvratil
Copy link
Collaborator
danvratil commented Jul 8, 2022

Can you please share what version of MSVC and CMake you have, how do you invoke CMake and what version of MSVC does clang-cl identify as when you run cmake? If possible, please provide the whole cmake command output.

As far as I can see, CMake should automatically enable exceptions. When I run CMake in Visual Studio, there's \EHsc set automatically, and so is in our CI. So I guess your case must be specific to either some version of CMake, MSVC or system configuration.

I'm not against adding those flags if it turns out they are really needed, but I want to make sure the issue is not specific to your setup/configuration and to understand why they are sometimes needed and sometimes not.

@danvratil danvratil added bug Something isn't working windows Windows/MSVC-specific issues labels Jul 8, 2022
@missdeer
Copy link
Author
missdeer commented Jul 9, 2022

I'm using the latest MSVC 2022 community edition with the latest clang-cl built from official git source, and qt-cmake.bat to generate Ninja project, got something like below:

>D:\qt\6.3.1\msvc2019_64\bin\qt-cmake.bat -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -G Ninja ..
-- The C compiler identification is Clang 15.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 15.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: F:/llvm/output/bin/clang-cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: F:/llvm/output/bin/clang-cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Failed
-- The following features have been enabled:

 * QtNetwork, Build QtNetwork support
 * QtWebSockets, Build QtWebSockets support

-- The following OPTIONAL packages have been found:

 * Qt6Core (required version >= 6.2.0)
 * Qt6Network (required version >= 6.2.0)
 * Qt6WebSockets (required version >= 6.2.0)
 * Qt6CoreTools

-- The following REQUIRED packages have been found:

 * Threads
 * Qt6

-- The following features have been disabled:

 * Examples, Build examples
 * Asan, Build with AddressSanitizer
 * QtDBus, Build QtDBus support

clang-cl version:

>clang-cl --version
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 8bc5e7ac519f04f83ca5e73322778ea0d5baa91f)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: F:\llvm\output\bin

cmake version:

>cmake --version
cmake version 3.23.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

@danvratil
Copy link
Collaborator

Thanks a lot, that explains it - with this setup you end up targeting the Windows-Clang-CXX platform rather than Windows-MSVC. MSVC requires that exceptions are enabled explicitly, so clang-cl copies that. CMake does enables exception for the Windows-MSVC platform, but does not for Windows-Clang-CXX.

danvratil added a commit that referenced this issue Jul 9, 2022
MSVC requires that exceptions are explicitly enabled using the `\EH`
flag, so clang-cl copies that behavior. When CMake targets the
Windows-MSVC platform (that is when using "Visual Studio" generator),
CMake takes care of adding `\EHsc` to `CXXFLAGS`. However when the
clang-cl compiler is specified manually (`CMAKE_CXX_COMPILER`) and
another generator, like Ninja is used, then CMake ends up targeting
the Windows-Clang-CXX platform, which does not enable exceptions,
so we have to do that ourselves. To keep the code simple, we do not
try to detect the target platform or such, we simply append the `\EHsc`
flag when we detect clang-cl.
@danvratil
Copy link
Collaborator

Could you please try #91 and confirm it fixes the problem?

@missdeer
Copy link
Author
missdeer commented Jul 9, 2022

Great! It works.

danvratil added a commit that referenced this issue Jul 9, 2022
Explicitly enable exception support for clang-cl (fixes #90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Windows/MSVC-specific issues
Projects
None yet
Development

No branches or pull requests

2 participants
0