Skip to content

Commit

Permalink
Fix compile error with _HAS_STATIC_RTTI=0 (#4046)
Browse files Browse the repository at this point in the history
  • Loading branch information
ALF-ONE committed Sep 24, 2023
1 parent bbd2e16 commit 6d4b72d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
31 changes: 31 additions & 0 deletions docs/mkdocs/docs/api/macros/json_has_static_rtti.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# JSON_HAS_STATIC_RTTI

```cpp
#define JSON_HAS_STATIC_RTTI /* value */
```
This macro indicates whether the standard library has any support for RTTI (run time type information).
Possible values are `1` when supported or `0` when unsupported.
## Default definition
The default value is detected based on the preprocessor macro `#!cpp _HAS_STATIC_RTTI`.
When the macro is not defined, the library will define it to its default value.
## Examples
??? example
The code below forces the library to enable support for libraries with RTTI dependence:
```cpp
#define JSON_HAS_STATIC_RTTI 1
#include <nlohmann/json.hpp>
...
```

## Version history

- Added in version ?.
8 changes: 8 additions & 0 deletions include/nlohmann/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
#endif
#endif

#ifndef JSON_HAS_STATIC_RTTI
#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
#define JSON_HAS_STATIC_RTTI 1
#else
#define JSON_HAS_STATIC_RTTI 0
#endif
#endif

#ifdef JSON_HAS_CPP_17
#define JSON_INLINE_VARIABLE inline
#else
Expand Down
1 change: 1 addition & 0 deletions include/nlohmann/detail/macro_unscope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#undef JSON_HAS_THREE_WAY_COMPARISON
#undef JSON_HAS_RANGES
#undef JSON_HAS_STATIC_RTTI
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#endif

Expand Down
6 changes: 4 additions & 2 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
#include <nlohmann/ordered_map.hpp>

#if defined(JSON_HAS_CPP_17)
#include <any>
#if JSON_HAS_STATIC_RTTI
#include <any>
#endif
#include <string_view>
#endif

Expand Down Expand Up @@ -1886,7 +1888,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
detail::negation<std::is_same<ValueType, std::string_view>>,
#endif
#if defined(JSON_HAS_CPP_17)
#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
detail::negation<std::is_same<ValueType, std::any>>,
#endif
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
Expand Down
15 changes: 13 additions & 2 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,14 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#endif
#endif

#ifndef JSON_HAS_STATIC_RTTI
#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
#define JSON_HAS_STATIC_RTTI 1
#else
#define JSON_HAS_STATIC_RTTI 0
#endif
#endif

#ifdef JSON_HAS_CPP_17
#define JSON_INLINE_VARIABLE inline
#else
Expand Down Expand Up @@ -19268,7 +19276,9 @@ NLOHMANN_JSON_NAMESPACE_END


#if defined(JSON_HAS_CPP_17)
#include <any>
#if JSON_HAS_STATIC_RTTI
#include <any>
#endif
#include <string_view>
#endif

Expand Down Expand Up @@ -21092,7 +21102,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
detail::negation<std::is_same<ValueType, std::string_view>>,
#endif
#if defined(JSON_HAS_CPP_17)
#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
detail::negation<std::is_same<ValueType, std::any>>,
#endif
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
Expand Down Expand Up @@ -24498,6 +24508,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#undef JSON_HAS_THREE_WAY_COMPARISON
#undef JSON_HAS_RANGES
#undef JSON_HAS_STATIC_RTTI
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#endif

Expand Down

0 comments on commit 6d4b72d

Please sign in to comment.