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