compile error using C++11 <thread>

compile error using C++11 <thread>

Greetings,

my env: MSVC 2012, both ICC 13 (the latest updates) and 14 (beta, the latest updates), Win8 x64

I was trying to convert WIN API CreateThread to make my C++11 code more cross-platform. I replaced it by inclusion of header <thread> and adjusted my code to use its functionality.

Sadly, I am unable to reproduce compile error with simple test case.

Errors I get are as follows:

C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(24): error : identifier "intmax_t" is undefined
    template<intmax_t _Val>
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(27): error : identifier "intmax_t" is undefined
        static const intmax_t value = _Val < 0 ? -_Val : _Val;
                     ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(31): error : identifier "intmax_t" is undefined
    template<intmax_t _Ax,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(32): error : identifier "intmax_t" is undefined
        intmax_t _Bx>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(35): error : identifier "intmax_t" is undefined
        static const intmax_t value = _GcdX<_Bx, _Ax % _Bx>::value;
                     ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(38): error : identifier "intmax_t" is undefined
    template<intmax_t _Ax>
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(38): error : constant "_Ax" is not used in or cannot be deduced from the template argument list of class template "std::_GcdX<<error-constant>, <error-constant>>"
    template<intmax_t _Ax>
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(44): error : identifier "intmax_t" is undefined
    template<intmax_t _Ax,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(45): error : identifier "intmax_t" is undefined
        intmax_t _Bx>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(48): error : identifier "intmax_t" is undefined
        static const intmax_t value =
                     ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(53): error : identifier "intmax_t" is undefined
    template<intmax_t _Nx, intmax_t _Dx = 1>
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(53): error : identifier "intmax_t" is undefined
    template<intmax_t _Nx, intmax_t _Dx = 1>
                           ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(64): error : identifier "intmax_t" is undefined
        static const intmax_t num =
                     ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(70): error : identifier "intmax_t" is undefined
        static const intmax_t den =
                     ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(74): error : expression must have a constant value
        typedef ratio<num, den> type;
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(74): error : expression must have a constant value
        typedef ratio<num, den> type;
                           ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(78): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(79): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(80): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(81): error : identifier "intmax_t" is undefined
        intmax_t _D2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(82): error : identifier "intmax_t" is undefined
        intmax_t _Gx>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(106): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(107): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(108): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(109): error : identifier "intmax_t" is undefined
        intmax_t _D2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(106): error : constant "_N1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_add2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
    template<intmax_t _N1,
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(107): error : constant "_D1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_add2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D1,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(108): error : constant "_N2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_add2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _N2,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(109): error : constant "_D2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_add2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D2>
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(130): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(131): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(132): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(133): error : identifier "intmax_t" is undefined
        intmax_t _D2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(130): error : constant "_N1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_subtract2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
    template<intmax_t _N1,
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(131): error : constant "_D1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_subtract2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D1,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(132): error : constant "_N2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_subtract2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _N2,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(133): error : constant "_D2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_subtract2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D2>
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(150): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(151): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(152): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(153): error : identifier "intmax_t" is undefined
        intmax_t _D2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(171): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(172): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(173): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(174): error : identifier "intmax_t" is undefined
        intmax_t _D2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(171): error : constant "_N1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_multiply2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
    template<intmax_t _N1,
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(172): error : constant "_D1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_multiply2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D1,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(173): error : constant "_N2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_multiply2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _N2,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(174): error : constant "_D2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_multiply2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D2>
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(196): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(197): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(198): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(199): error : identifier "intmax_t" is undefined
        intmax_t _D2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(196): error : constant "_N1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_divide2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
    template<intmax_t _N1,
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(197): error : constant "_D1" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_divide2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D1,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(198): error : constant "_N2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_divide2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _N2,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(199): error : constant "_D2" is not used in or cannot be deduced from the template argument list of class template "std::_Ratio_divide2<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D2>
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(224): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(225): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(226): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(227): error : identifier "intmax_t" is undefined
        intmax_t _D2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(224): error : constant "_N1" is not used in or cannot be deduced from the template argument list of class template "std::ratio_equal<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
    template<intmax_t _N1,
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(225): error : constant "_D1" is not used in or cannot be deduced from the template argument list of class template "std::ratio_equal<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D1,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(226): error : constant "_N2" is not used in or cannot be deduced from the template argument list of class template "std::ratio_equal<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _N2,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(227): error : constant "_D2" is not used in or cannot be deduced from the template argument list of class template "std::ratio_equal<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D2>
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(246): error : identifier "intmax_t" is undefined
    template<intmax_t _N1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(247): error : identifier "intmax_t" is undefined
        intmax_t _D1,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(248): error : identifier "intmax_t" is undefined
        intmax_t _N2,
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(249): error : identifier "intmax_t" is undefined
        intmax_t _D2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(246): error : constant "_N1" is not used in or cannot be deduced from the template argument list of class template "std::ratio_less<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
    template<intmax_t _N1,
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(247): error : constant "_D1" is not used in or cannot be deduced from the template argument list of class template "std::ratio_less<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D1,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(248): error : constant "_N2" is not used in or cannot be deduced from the template argument list of class template "std::ratio_less<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _N2,
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(249): error : constant "_D2" is not used in or cannot be deduced from the template argument list of class template "std::ratio_less<std::ratio<<error-constant>, <error-constant>>, std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _D2>
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(55): error : identifier "intmax_t" is undefined
    template<intmax_t _R1,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(56): error : identifier "intmax_t" is undefined
        intmax_t _R2>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(55): error : constant "_R1" is not used in or cannot be deduced from the template argument list of class template "std::chrono::_Is_ratio<std::ratio<<error-constant>, <error-constant>>>"
    template<intmax_t _R1,
                      ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(56): error : constant "_R2" is not used in or cannot be deduced from the template argument list of class template "std::chrono::_Is_ratio<std::ratio<<error-constant>, <error-constant>>>"
        intmax_t _R2>
                 ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(302): error : identifier "intmax_t" is undefined
    template<intmax_t _Ax,
             ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(303): error : identifier "intmax_t" is undefined
        intmax_t _Bx>
        ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(306): error : identifier "intmax_t" is undefined
        static const intmax_t _Gx = _Gcd<_Ax, _Bx>::value;
                     ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono(307): error : identifier "intmax_t" is undefined
        static const intmax_t value = (_Ax / _Gx) * _Bx;
                     ^
  
C:Program Files (x86)Microsoft Visual Studio 11.0VCincluderatio(188): error : incomplete type is not allowed
        typedef typename _Ratio_multiply2<_R1, _R2>::type type;
                         ^
            detected during instantiation of class "std::ratio_multiply<_R1, _R2> [with _R1=std::ratio<<error-constant>, <error-constant>>, _R2=std::nano]" at line 697 of "C:Program Files (x86)Microsoft Visual Studio 11.0VCincludechrono"
  
Build FAILED.

When I remove "#include <thread>" from pre-compiled header file, these errors disappear, and it compiles just fine.

Any suggestions?

--
With best regards,
VooDooMan
-
If you find my post helpful, please rate it and/or select it as a best answer where applies. Thank you.
7 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

An intmax_t type is declared in stdint.h and cstdint header files ( introduced in VS 2010 ). Please verify that one of these headers is included in your sources ( I recommend to add it in stdafx.h header file ).

Hello Sergey,

Yes, I did it before your post.

My #include's looks like:

#include <cstdint>
#include <stdint.h>
#include <thread>

(and after all "using namespace std;").

and I am getting the very same compile errors. Am I missing something? Or is it a bug in MSVC/ICC?

--
With best regards,
VooDooMan
-
If you find my post helpful, please rate it and/or select it as a best answer where applies. Thank you.

Here are how some another types are declared and I don't see any problems:

[ stdint.h ]

...
#ifndef _INTPTR_T_DEFINED
#define _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else /* _WIN64 */
typedef _W64 int intptr_t;
#endif /* _WIN64 */
#endif /* _INTPTR_T_DEFINED */

#ifndef _UINTPTR_T_DEFINED
#define _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else /* _WIN64 */
typedef _W64 unsigned int uintptr_t;
#endif /* _WIN64 */
#endif /* _UINTPTR_T_DEFINED */

typedef _Longlong int64_t;
typedef _ULonglong uint64_t;

typedef _Longlong int_least64_t;
typedef _ULonglong uint_least64_t;

typedef _Longlong int_fast64_t;
typedef _ULonglong uint_fast64_t;

typedef _Longlong intmax_t;
typedef _ULonglong uintmax_t;
...

The _Longlong is declared in yvals.h header file.

As Sergey points out, every one of those errors is a result of "intmax_t" not being a defined type.  Likely, the WinAPI header you were using for threads contained an include for the definition of that type, and when you stopped using it this error popped up and was incorrectly attributed to threading.

Your test case for this error is: (compiles correctly in the lastest update of 13.x on Linux)

#include <stdint.h>
// including <cstdint> also works
int main()
{
 intmax_t test;
 return 0;
}

If you omit stdint.h, this testcase emits the error in your OP.

Greetings,

finally I have figured out what was causing the problem. One of 3rd party library had it's own "stdint.h" and it was getting higher precedence with #include than standard library's one.

I have adjusted the 3rd party library and called the file "my_stdint.h" and everything is just fine now.

--
With best regards,
VooDooMan
-
If you find my post helpful, please rate it and/or select it as a best answer where applies. Thank you.

Thanks for the update, Narian.

>>...One of 3rd party library had it's own "stdint.h"...

Is that an Open Source 3rd party library and which one? Let us know ( if it is possible ).

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi