Skip to content

Commit 6dc4242

Browse files
committed
Stop static analysis on constexpr schema test
1 parent a80919b commit 6dc4242

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

include/json2cpp/constexpr_json.hpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#include <variant>
1010

1111
namespace constexpr_json {
12+
template<typename First, typename Second> struct pair
13+
{
14+
First first;
15+
Second second;
16+
};
17+
1218
template<typename T> struct span
1319
{
1420
template<std::size_t Size>
@@ -28,7 +34,8 @@ template<typename T> struct span
2834
struct json;
2935

3036
using array_t = span<json>;
31-
using object_t = span<std::pair<std::string_view, json>>;
37+
using value_pair_t = pair<std::string_view, json>;
38+
using object_t = span<value_pair_t>;
3239
using binary_t = span<std::uint8_t>;
3340

3441
using data_t = std::
@@ -76,10 +83,7 @@ struct json
7683
{
7784
return other.parent_value_ == parent_value_ && other.index_ == index_;
7885
}
79-
constexpr bool operator!=(const iterator &other) const
80-
{
81-
return !(*this == other);
82-
}
86+
constexpr bool operator!=(const iterator &other) const { return !(*this == other); }
8387

8488

8589
constexpr bool operator<(const iterator &other) const
@@ -116,17 +120,12 @@ struct json
116120

117121
constexpr iterator cend() const { return end(); }
118122

119-
constexpr std::size_t size() const noexcept {
120-
if (is_null()) {
121-
return 0;
122-
}
123-
if (is_object()) {
124-
return std::get_if<object_t>(&data)->size();
125-
}
123+
constexpr std::size_t size() const noexcept
124+
{
125+
if (is_null()) { return 0; }
126+
if (is_object()) { return std::get_if<object_t>(&data)->size(); }
126127

127-
if (is_array()) {
128-
return std::get_if<array_t>(&data)->size();
129-
}
128+
if (is_array()) { return std::get_if<array_t>(&data)->size(); }
130129

131130
return 1;
132131
}
@@ -185,16 +184,28 @@ struct json
185184

186185
constexpr double as_number_float() const
187186
{
188-
if (const double *value = std::get_if<double>(&data); value != nullptr) { return *value; }
187+
if (const double *value = std::get_if<double>(&data); value != nullptr) {
188+
return *value;
189+
} else {
190+
throw std::runtime_error("Not a float type");
191+
}
189192
}
190193
constexpr double as_boolean() const
191194
{
192-
if (const bool *value = std::get_if<bool>(&data); value != nullptr) { return *value; }
195+
if (const bool *value = std::get_if<bool>(&data); value != nullptr) {
196+
return *value;
197+
} else {
198+
throw std::runtime_error("Not a boolean type");
199+
}
193200
}
194201

195202
constexpr std::string_view as_string() const
196203
{
197-
if (const auto *value = std::get_if<std::string_view>(&data); value != nullptr) { return *value; }
204+
if (const auto *value = std::get_if<std::string_view>(&data); value != nullptr) {
205+
return *value;
206+
} else {
207+
throw std::runtime_error("Not a string type");
208+
}
198209
}
199210

200211
constexpr operator double() const { return as_number_float(); }
@@ -219,7 +230,6 @@ struct json
219230
data_t data;
220231
};
221232

222-
using value_pair_t = std::pair<std::string_view, json>;
223233
}// namespace constexpr_json
224234

225235
#endif

test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ target_link_libraries(constexpr_schema_tests PRIVATE project_options project_war
9696
target_include_directories(constexpr_schema_tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
9797
target_include_directories(constexpr_schema_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
9898

99+
# disable analysis for these very large generated bits of code
100+
set_target_properties(constexpr_schema_tests PROPERTIES CXX_CPPCHECK "" CXX_CLANG_TIDY "")
99101

100102
catch_discover_tests(
101103
constexpr_schema_tests
@@ -118,6 +120,10 @@ target_compile_definitions(relaxed_constexpr_schema_tests PRIVATE -DCATCH_CONFIG
118120
target_include_directories(relaxed_constexpr_schema_tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
119121
target_include_directories(relaxed_constexpr_schema_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
120122

123+
# disable analysis for these very large generated bits of code
124+
set_target_properties(relaxed_constexpr_schema_tests PROPERTIES CXX_CPPCHECK "" CXX_CLANG_TIDY "")
125+
126+
121127

122128
catch_discover_tests(
123129
relaxed_constexpr_schema_tests

0 commit comments

Comments
 (0)