'C2039 and C2873 when including `<cctype>` from the STL

I'm trying to compile a project with msvc 2019 compilers that I know has been compiled before. In fact, I'm actually updating the build system for it. I've come across a strange problem with sources from the standard template library. Basically the project includes <cctype> which pulls in the following snippet:

_STD_BEGIN
using _CSTD isalnum;
using _CSTD isalpha;
using _CSTD iscntrl;
using _CSTD isdigit;
using _CSTD isgraph;
using _CSTD islower;
using _CSTD isprint;
using _CSTD ispunct;
using _CSTD isspace;
using _CSTD isupper;
using _CSTD isxdigit;
using _CSTD tolower;
using _CSTD toupper;

using _CSTD isblank;
_STD_END

But these declarations all error with the following when I compile my project.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(38): error C2039: 'isalnum': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(38): error C2873: 'isalnum': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(39): error C2039: 'isalpha': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(39): error C2873: 'isalpha': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(40): error C2039: 'iscntrl': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(40): error C2873: 'iscntrl': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(41): error C2039: 'isdigit': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(41): error C2873: 'isdigit': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(42): error C2039: 'isgraph': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(42): error C2873: 'isgraph': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(43): error C2039: 'islower': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(43): error C2873: 'islower': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(44): error C2039: 'isprint': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(44): error C2873: 'isprint': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(45): error C2039: 'ispunct': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(45): error C2873: 'ispunct': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(46): error C2039: 'isspace': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(46): error C2873: 'isspace': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(47): error C2039: 'isupper': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(47): error C2873: 'isupper': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(48): error C2039: 'isxdigit': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(48): error C2873: 'isxdigit': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(49): error C2039: 'tolower': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(49): error C2873: 'tolower': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(50): error C2039: 'toupper': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(50): error C2873: 'toupper': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(52): error C2039: 'isblank': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(52): error C2873: 'isblank': symbol cannot be used in a using-declaration

The result is the same with both c++11 and c++14. I attempted to make a minimal working example but could not because my toy project that includes and uses <cctype> compiles without problems. Therefore it must be a problem with my project settings somewhere.

I know this is going to be a tough one, but does anybody have any thoughts on what might be happening here?



Solution 1:[1]

I had the same error on the macOS platform; the solution for me was to #include <_ctype.h> - this header defines the is* functions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 François Kupo