Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VC++ compile the code while clang doesn't?

I use VS 2015 (Update 3) to compile the following code:

#include <codecvt>
#include <cctype>
#include <functional>

int main()
{
    std::function<int(int)> fn = std::isspace;
}

If I use VC++ to compile it, it's ok. However, if I change the compiler to Visual Studio 2015 - Clang with Microsoft CodeGen (v140_clang_c2) in Visual Studio, clang reports an error:

main.cpp(7,26): error : no viable conversion from '' to 'std::function'

std::function fn = std::isspace;

More surprising, if I comments the first line as follows, clang will also be ok.

//#include <codecvt> // now clang feels happy
#include <cctype>
#include <functional>

int main()
{
    std::function<int(int)> fn = std::isspace;
}

What's the root cause?

like image 622
xmllmx Avatar asked Dec 25 '22 02:12

xmllmx


1 Answers

std::isspace is overloaded in the standard library.

Due to the structure of their standard library headers, one compiler sees two different declarations of the name.

Then its use without arguments or casting is ambiguous.

like image 100
Cheers and hth. - Alf Avatar answered Jan 04 '23 21:01

Cheers and hth. - Alf