e24d30dd4b55db17e7a0fb06ca1fe943dfc3219c
[libcds.git] / cds / compiler / vc / defs.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_COMPILER_VC_DEFS_H
4 #define __CDS_COMPILER_VC_DEFS_H
5 //@cond
6
7 // Compiler version
8 #define CDS_COMPILER_VERSION    _MSC_VER
9
10 // Compiler name
11 // Supported compilers: MS VC 2008, 2010, 2012, 2013
12 // C++ compiler versions:
13 #define CDS_COMPILER_MSVC9  1500    // 2008 vc9
14 #define CDS_COMPILER_MSVC10 1600    // 2010 vc10
15 #define CDS_COMPILER_MSVC11 1700    // 2012 vc11
16 #define CDS_COMPILER_MSVC12 1800    // 2013 vc12
17
18 #if _MSC_VER == 1500
19 #   define  CDS_COMPILER__NAME  "MS Visual C++ 2008"
20 #   define  CDS_COMPILER__NICK  "vc9"
21 #elif _MSC_VER == 1600
22 #   define  CDS_COMPILER__NAME  "MS Visual C++ 2010"
23 #   define  CDS_COMPILER__NICK  "vc10"
24 #elif _MSC_VER == 1700
25 #   define  CDS_COMPILER__NAME  "MS Visual C++ 2012"
26 #   define  CDS_COMPILER__NICK  "vc11"
27 #elif _MSC_VER == 1800
28 #   define  CDS_COMPILER__NAME  "MS Visual C++ 2013"
29 #   define  CDS_COMPILER__NICK  "vc12"
30 #else
31 #   define  CDS_COMPILER__NAME  "MS Visual C++"
32 #   define  CDS_COMPILER__NICK  "msvc"
33 #endif
34
35 // OS interface
36 #define CDS_OS_INTERFACE CDS_OSI_WINDOWS
37
38 // OS name
39 #if defined(_WIN64)
40 #   define CDS_OS_TYPE      CDS_OS_WIN64
41 #   define CDS_OS__NAME     "Win64"
42 #   define CDS_OS__NICK     "Win64"
43 #elif defined(_WIN32)
44 #   define CDS_OS_TYPE      CDS_OS_WIN32
45 #   define CDS_OS__NAME     "Win32"
46 #   define CDS_OS__NICK     "Win32"
47 #endif
48
49 // Processor architecture
50 #ifdef _M_IX86
51 #   define CDS_BUILD_BITS       32
52 #   define CDS_PROCESSOR_ARCH   CDS_PROCESSOR_X86
53 #   define CDS_PROCESSOR__NAME  "Intel x86"
54 #   define CDS_PROCESSOR__NICK  "x86"
55 #elif _M_X64
56 #   define CDS_BUILD_BITS       64
57 #   define CDS_PROCESSOR_ARCH   CDS_PROCESSOR_AMD64
58 #   define CDS_PROCESSOR__NAME  "AMD64"
59 #   define CDS_PROCESSOR__NICK  "amd64"
60 #else
61 #   define CDS_BUILD_BITS        -1
62 #   define CDS_PROCESSOR_ARCH    CDS_PROCESSOR_UNKNOWN
63 #   define CDS_PROCESSOR__NAME    "<<Undefined>>"
64 #   error Microsoft Visual C++ compiler is supported for x86 only
65 #endif
66
67
68 #define  __attribute__( _x )
69
70 #define  CDS_STDCALL    __stdcall
71
72 #ifdef CDS_BUILD_LIB
73 #   define CDS_EXPORT_API          __declspec(dllexport)
74 #else
75 #   define CDS_EXPORT_API          __declspec(dllimport)
76 #endif
77
78 #define alignof     __alignof
79
80 #if CDS_COMPILER_VERSION < 1600
81 #   include <boost/static_assert.hpp>
82 #   define static_assert(_expr, _msg)     BOOST_STATIC_ASSERT((_expr))
83 #endif
84
85 // Memory leaks detection (debug build only)
86 #ifdef _DEBUG
87 #   define _CRTDBG_MAP_ALLOC
88 #   define _CRTDBG_MAPALLOC
89 #   include <stdlib.h>
90 #   include <crtdbg.h>
91 #   define CDS_MSVC_MEMORY_LEAKS_DETECTING_ENABLED
92 #endif
93
94 // constexpr is not yet supported
95 #define CDS_CONSTEXPR
96 #define CDS_CONSTEXPR_CONST const
97
98 // noexcept is not yet supported
99 //#define CDS_NOEXCEPT_SUPPORT        noexcept
100 //#define CDS_NOEXCEPT_SUPPORT_(expr) noexcept(expr)
101 #define CDS_NOEXCEPT_SUPPORT
102 #define CDS_NOEXCEPT_SUPPORT_(expr)
103
104 // C++11 atomic support
105 // MSVC 2012 has <atomic> implementation but all load/store is based on CAS
106 // that is quite inefficient.
107 // So for VC 2012 we use internal implementation for atomics
108 #if CDS_COMPILER_VERSION >= 1800
109 #   define CDS_CXX11_ATOMIC_SUPPORT     1
110 #endif
111
112
113 // Lambda (VC 10 +)
114 #if CDS_COMPILER_VERSION >= 1600
115 #   define CDS_CXX11_LAMBDA_SUPPORT
116 #   if CDS_COMPILER_VERSION < 1700
117 #       define CDS_BUG_STATIC_MEMBER_IN_LAMBDA
118 #   endif
119 #endif
120
121 // RValue (VC 10+)
122 #if CDS_COMPILER_VERSION >= 1600
123 #   define CDS_RVALUE_SUPPORT
124 #   define CDS_MOVE_SEMANTICS_SUPPORT
125 #endif
126
127 // Default template arguments for function templates (VC12+)
128 #if CDS_COMPILER_VERSION >= 1800
129 #   define CDS_CXX11_DEFAULT_FUNCTION_TEMPLATE_ARGS_SUPPORT
130 #endif
131
132 // C++11 delete definition ( function declaration = delete)
133 #if CDS_COMPILER_VERSION >= 1800
134 #   define CDS_CXX11_DELETE_DEFINITION_SUPPORT
135 #endif
136
137 // C++11 explicitly-defaulted function (= default) [std 8.4.2 [dcl.fct.def.default]]
138 #if CDS_COMPILER_VERSION >= 1800
139 #   define CDS_CXX11_EXPLICITLY_DEFAULTED_FUNCTION_SUPPORT
140 #endif
141
142 // Variadic template support (VC12+)
143 #if CDS_COMPILER_VERSION >= 1800
144 #   define CDS_CXX11_VARIADIC_TEMPLATE_SUPPORT     1
145 #endif
146
147 // C++11 template alias
148 #if CDS_COMPILER_VERSION >= 1800
149 #   define CDS_CXX11_TEMPLATE_ALIAS_SUPPORT
150 #endif
151
152 // C++11 inline namespace
153 //#define CDS_CXX11_INLINE_NAMESPACE_SUPPORT
154
155 // Explicit conversion operator (VC12+)
156 #if CDS_COMPILER_VERSION >= 1800
157 #   define CDS_CXX11_EXPLICIT_CONVERSION_OPERATOR_SUPPORT
158 #endif
159
160
161 // <cstdint>
162 #if CDS_COMPILER_VERSION == 1500
163     // MS VC 2008 has no <cstdint>
164 #   include <cds/compiler/cstdint_boost.h>
165 #else
166 #   include <cds/compiler/cstdint_std.h>
167 #endif
168
169 // Thread support library (thread, mutex, condition variable)
170 #if CDS_COMPILER_VERSION >= 1700
171     // MS VC 11+
172 #   define CDS_CXX11_STDLIB_THREAD
173 #   define CDS_CXX11_STDLIB_MUTEX
174 #   define CDS_CXX11_STDLIB_CONDITION_VARIABLE
175 #   define CDS_CXX11_STDLIB_CHRONO
176 #endif
177
178 // Full SFINAE support
179 //#if CDS_COMPILER_VERSION >= ????
180 //#   define CDS_CXX11_SFINAE
181 //#endif
182
183
184 // *************************************************
185 // Alignment macro
186
187 // VC 2005 generates error C2719 "formal parameter with __declspec(align('#')) won't be aligned"
188 // for function's formal parameter with align declspec
189 #define CDS_TYPE_ALIGNMENT(n)     __declspec( align(n) )
190 #define CDS_DATA_ALIGNMENT(n)     __declspec( align(n) )
191 #define CDS_CLASS_ALIGNMENT(n)    __declspec( align(n) )
192
193 #include <cds/compiler/vc/compiler_barriers.h>
194
195 //@endcond
196 #endif // #ifndef __CDS_COMPILER_VC_DEFS_H