clang-cl -EHsc and extern C noexcept

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

clang-cl -EHsc and extern C noexcept

Manuel Klimek via cfe-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang-cl -EHsc and extern C noexcept

Manuel Klimek via cfe-dev
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 <[hidden email]> 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev