Visual Studio 2017: ambiguous size_t character in linux projects

In Visual Studio 2017, when creating a Linux project and pasting using namespace std;into source code:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    size_t i = 1;
    string s = to_string(i);
    cout << i << s << endl;
    return 0;
}

VS emphasizes size_tand says that it is an ambiguous symbol.VS pic 1

If I press F12 ( Go to definition), it will offer me two definitions:

From stddef.h

( C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include\x86_64-linux-gnu\5\include\stddef.h):

// ...
namespace std
{
  typedef __SIZE_TYPE__     size_t;
// ...

AND c++config.h

( C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include\x86_64-linux-gnu\c++\5\bits\c++config.h):

// ...
#if !(defined (__GNUG__) && defined (size_t))
typedef __SIZE_TYPE__ size_t;
// ...

This only happens with Linux projects in VS, not with Windows projects.

Is there a known solution (except "do not use using namespace std;:))?

Update . This Microsoft issue has been reported: https://developercommunity.visualstudio.com/content/problem/67405/ambiguous-symbol-size-t-in-linux-projects-when-usi.html

Upd2. Microsoft , , : https://developercommunity.visualstudio.com/content/problem/67405/ambiguous-symbol-size-t-in-linux-projects-when-usi.html

+4
1

, Microsoft , typedef .

namespace foo { typedef int moo; }
typedef int moo;
using namespace foo;
extern moo a;

g++ clang++ ( -Weverything). MSVC - .

size_t gcc. , namespace std. , , g++.

g++, msvc? , - 7.1.3/3

typedef , , , .

, g++ . moo namespace ::, , , . , ​​.

, , size_t , namespace std (, __cplusplus ). ( VC2017) , .

, IntelliSense. . (update). MSVC. , , " " gcc, MSVC).

+5

Source: https://habr.com/ru/post/1678985/


All Articles