clang-cl -EHsc and extern C noexcept

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

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.


$ 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.

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.