Skip to content

Commit bdd1729

Browse files
committed
fix C++ standard detection on MSVC compiler
1 parent 7060117 commit bdd1729

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

src/utki/config.hpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,6 @@ SOFTWARE.
3030

3131
// NOLINTBEGIN
3232

33-
//====================================================|
34-
// C++ standard |
35-
// |
36-
37-
#if __cplusplus > 201703L
38-
# define CFG_CPP 20
39-
#elif __cplusplus > 201402L
40-
# define CFG_CPP 17
41-
#elif __cplusplus > 201103L
42-
# define CFG_CPP 14
43-
#elif __cplusplus > 199711L
44-
# define CFG_CPP 11
45-
#else
46-
# define CFG_CPP 3
47-
#endif
48-
4933
//======================================|
5034
// OS definitions |
5135
// |
@@ -165,6 +149,31 @@ SOFTWARE.
165149
# define CFG_COMPILER CFG_COMPILER_UNKNOWN
166150
#endif
167151

152+
//====================================================|
153+
// C++ standard |
154+
// |
155+
156+
// In MSVC the __cplusplus macro is not set according to the actual standard used,
157+
// this is done as a workaround for legacy software which relied on __cplusplus being
158+
// certain values. To get the actual C++ standard in MSVC the _MSVC_LANG macro should be used.
159+
#if CFG_COMPILER == CFG_COMPILER_MSVC
160+
# define UTKI_CPP_STANDARD _MSVC_LANG
161+
#else
162+
# define UTKI_CPP_STANDARD __cplusplus
163+
#endif
164+
165+
#if UTKI_CPP_STANDARD > 201703L
166+
# define CFG_CPP 20
167+
#elif UTKI_CPP_STANDARD > 201402L
168+
# define CFG_CPP 17
169+
#elif UTKI_CPP_STANDARD > 201103L
170+
# define CFG_CPP 14
171+
#elif UTKI_CPP_STANDARD > 199711L
172+
# define CFG_CPP 11
173+
#else
174+
# define CFG_CPP 3
175+
#endif
176+
168177
//====================================================|
169178
// CPU architecture definitions |
170179
// |

0 commit comments

Comments
 (0)