Skip to content

Commit 6d4b72d

Browse files
authored
Fix compile error with _HAS_STATIC_RTTI=0 (#4046)
1 parent bbd2e16 commit 6d4b72d

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# JSON_HAS_STATIC_RTTI
2+
3+
```cpp
4+
#define JSON_HAS_STATIC_RTTI /* value */
5+
```
6+
7+
This macro indicates whether the standard library has any support for RTTI (run time type information).
8+
Possible values are `1` when supported or `0` when unsupported.
9+
10+
## Default definition
11+
12+
The default value is detected based on the preprocessor macro `#!cpp _HAS_STATIC_RTTI`.
13+
14+
When the macro is not defined, the library will define it to its default value.
15+
16+
## Examples
17+
18+
??? example
19+
20+
The code below forces the library to enable support for libraries with RTTI dependence:
21+
22+
```cpp
23+
#define JSON_HAS_STATIC_RTTI 1
24+
#include <nlohmann/json.hpp>
25+
26+
...
27+
```
28+
29+
## Version history
30+
31+
- Added in version ?.

include/nlohmann/detail/macro_scope.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@
133133
#endif
134134
#endif
135135

136+
#ifndef JSON_HAS_STATIC_RTTI
137+
#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
138+
#define JSON_HAS_STATIC_RTTI 1
139+
#else
140+
#define JSON_HAS_STATIC_RTTI 0
141+
#endif
142+
#endif
143+
136144
#ifdef JSON_HAS_CPP_17
137145
#define JSON_INLINE_VARIABLE inline
138146
#else

include/nlohmann/detail/macro_unscope.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
3939
#undef JSON_HAS_THREE_WAY_COMPARISON
4040
#undef JSON_HAS_RANGES
41+
#undef JSON_HAS_STATIC_RTTI
4142
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
4243
#endif
4344

include/nlohmann/json.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
#include <nlohmann/ordered_map.hpp>
6363

6464
#if defined(JSON_HAS_CPP_17)
65-
#include <any>
65+
#if JSON_HAS_STATIC_RTTI
66+
#include <any>
67+
#endif
6668
#include <string_view>
6769
#endif
6870

@@ -1886,7 +1888,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
18861888
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
18871889
detail::negation<std::is_same<ValueType, std::string_view>>,
18881890
#endif
1889-
#if defined(JSON_HAS_CPP_17)
1891+
#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
18901892
detail::negation<std::is_same<ValueType, std::any>>,
18911893
#endif
18921894
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>

single_include/nlohmann/json.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,14 @@ JSON_HEDLEY_DIAGNOSTIC_POP
24852485
#endif
24862486
#endif
24872487

2488+
#ifndef JSON_HAS_STATIC_RTTI
2489+
#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
2490+
#define JSON_HAS_STATIC_RTTI 1
2491+
#else
2492+
#define JSON_HAS_STATIC_RTTI 0
2493+
#endif
2494+
#endif
2495+
24882496
#ifdef JSON_HAS_CPP_17
24892497
#define JSON_INLINE_VARIABLE inline
24902498
#else
@@ -19268,7 +19276,9 @@ NLOHMANN_JSON_NAMESPACE_END
1926819276

1926919277

1927019278
#if defined(JSON_HAS_CPP_17)
19271-
#include <any>
19279+
#if JSON_HAS_STATIC_RTTI
19280+
#include <any>
19281+
#endif
1927219282
#include <string_view>
1927319283
#endif
1927419284

@@ -21092,7 +21102,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
2109221102
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
2109321103
detail::negation<std::is_same<ValueType, std::string_view>>,
2109421104
#endif
21095-
#if defined(JSON_HAS_CPP_17)
21105+
#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
2109621106
detail::negation<std::is_same<ValueType, std::any>>,
2109721107
#endif
2109821108
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
@@ -24498,6 +24508,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
2449824508
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2449924509
#undef JSON_HAS_THREE_WAY_COMPARISON
2450024510
#undef JSON_HAS_RANGES
24511+
#undef JSON_HAS_STATIC_RTTI
2450124512
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
2450224513
#endif
2450324514

0 commit comments

Comments
 (0)