Pol  Revision:4b29d2b
compilerspecifics.h
Go to the documentation of this file.
1 /*
2 ATTENTION:
3 This header is part of the PCH
4 Remove the include in all StdAfx.h files or live with the consequences :)
5 */
6 
7 #ifndef CLIB_COMPILERSPECIFICS_H_
8 #define CLIB_COMPILERSPECIFICS_H_
9 
10 // Fix for VS CodeAnalysis
11 #ifdef _MSC_VER
12 #pragma warning( disable : 4467 ) // ATL attributes
13 #include <CodeAnalysis/sourceannotations.h>
14 #define passert_assume( x ) __analysis_assume( x )
15 #else
16 #define passert_assume( x )
17 #endif
18 
19 
20 // Defines noreturn attribute using VC++ specifics, C++11-way for modern compilers. :P
21 // Note: noreturn can be used for code-generation and is supposed to produce more optimized code
22 #ifndef POL_NORETURN
23 #if defined( _MSC_VER )
24 #define POL_NORETURN _declspec( noreturn )
25 #elif defined( __clang__ )
26 #define POL_NORETURN [[noreturn]]
27 #elif defined( __GNUC__ )
28 #define POL__GCC_VERSION ( __GNUC__ * 100 + __GNUC_MINOR__ )
29 #if POL__GCC_VERSION <= 407
30 #define POL_NORETURN __attribute__( ( noreturn ) )
31 #else
32 #define POL_NORETURN [[noreturn]]
33 #endif
34 #undef POL__GCC_VERSION
35 #else
36 #define POL_NORETURN [[noreturn]]
37 #endif
38 #endif
39 
40 // Note: POL_ANALYZER_NORETURN is just a hint for code analyzers (mostly clang-analyzer) and is not
41 // used for code generation. I don't know of anything similar in the other analyzers and
42 // thought
43 // of using POL_NORETURN here. Right now I'm not sure if this is needed at all.
44 #ifndef POL_ANALYZER_NORETURN
45 #ifndef __has_feature
46 #define __has_feature( x ) 0
47 #endif
48 #if __has_feature( attribute_analyzer_noreturn )
49 #define POL_ANALYZER_NORETURN __attribute__( ( analyzer_noreturn ) )
50 #else
51 #define POL_ANALYZER_NORETURN
52 #endif
53 #endif
54 
55 // override and final makros
56 #ifndef POL_OVERRIDE
57 #if defined( _MSC_VER )
58 #define POL_OVERRIDE override
59 #define POL_FINAL final
60 #elif defined( __clang__ )
61 #define POL_OVERRIDE override
62 #define POL_FINAL final
63 #elif defined( __GNUC__ )
64 #define POL__GCC_VERSION ( __GNUC__ * 100 + __GNUC_MINOR__ )
65 #if POL__GCC_VERSION < 407
66 #define POL_OVERRIDE
67 #define POL_FINAL
68 #else
69 #define POL_OVERRIDE override
70 #define POL_FINAL final
71 #endif
72 #undef POL__GCC_VERSION
73 #else
74 #define POL_OVERRIDE
75 #define POL_FINAL
76 #endif
77 #endif
78 
79 
80 // the following code to handle NOEXCEPT was obtained
81 // from http://stackoverflow.com/questions/18387640/how-to-deal-with-noexcept-in-visual-studio
82 #if !defined( HAS_NOEXCEPT )
83 #if defined( __clang__ )
84 #if __has_feature( cxx_noexcept )
85 #define HAS_NOEXCEPT
86 #endif
87 #else
88 #if defined( __GXX_EXPERIMENTAL_CXX0X__ ) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \
89  defined( _MSC_FULL_VER ) && _MSC_FULL_VER >= 190023026
90 #define HAS_NOEXCEPT
91 #endif
92 #endif
93 
94 #ifdef HAS_NOEXCEPT
95 #define POL_NOEXCEPT noexcept
96 #else
97 #define POL_NOEXCEPT
98 #endif
99 #endif
100 
101 #if ( !defined( _MSC_VER ) || _MSC_VER >= 1900 )
102 #define THREADLOCAL thread_local
103 #else
104 #define THREADLOCAL __declspec( thread )
105 #endif
106 
107 #if ( !defined( _MSC_VER ) || _MSC_VER >= 1900 )
108 #define CONSTEXPR constexpr
109 #else
110 #define CONSTEXPR
111 #endif
112 #endif