[cfe-dev] clang-cl -EHsc and extern C noexcept

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Sat Mar 31 18:30:41 PDT 2018


That's interesting. When we consulted the documentation, I interpreted /EHc
as applying "nounwind" to every function or "throw()". Those are different
from noexcept in that they don't interact with the type system (as you've
discovered) and they don't emit runtime checks that cause the program to
exit if this assumption is violated.

On Sat, Mar 31, 2018 at 3:54 PM Tiago Macarios via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> The code below compiles fine with cl, but fails with clang-cl. Do I need
> to add extra flags so that -EHsc treats extern C functions as noexcept? Or
> am I missing something?
>
> $ cat f.cpp
> #include <cstring>
>
> template<typename Tch, int (__cdecl *pfnCompare)(const Tch* tz1, const
> Tch* tz2) noexcept>
> static int Compare_impl(const Tch* tz1, const Tch* tz2) noexcept
> {
>     return pfnCompare(tz1, tz2);
> }
>
> int Compare(const char* sz1, const char* sz2) noexcept
> {
>     return Compare_impl<char, strcmp>(sz1, sz2);
> }
>
>
> $ cl -EHsc -std:c++17 -c f.cpp
> Microsoft (R) C/C++ Optimizing Compiler Version 19.13.26129 for x64
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
> f.cpp
>
> $ clang-cl -EHsc -std:c++17 -c f.cpp
> f.cpp(11,12):  error: no matching function for call to 'Compare_impl'
>     return Compare_impl<char, strcmp>(sz1, sz2);
>            ^~~~~~~~~~~~~~~~~~~~~~~~~~
> f.cpp(4,12):  note: candidate template ignored: invalid
> explicitly-specified argument for template parameter 'pfnCompare'
> static int Compare_impl(const Tch* tz1, const Tch* tz2) noexcept
>            ^
> 1 error generated.
>
> If I remove the noexcept(s) in the files everything works fine.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180401/ce1dc08e/attachment.html>


More information about the cfe-dev mailing list