Skip to content

Commit a1cf588

Browse files
committed
Fix GCC 7 warning when inlining does its job
1 parent dfc510f commit a1cf588

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

include/simdjson/common_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
100100
#endif
101101

102102
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
103+
#define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
103104
#define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
104105

105106
#else // SIMDJSON_REGULAR_VISUAL_STUDIO
@@ -139,6 +140,7 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
139140
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
140141
#endif
141142
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
143+
#define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wstrict-overflow)
142144
#define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
143145

144146

include/simdjson/generic/ondemand/json_iterator-inl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ simdjson_really_inline json_iterator::json_iterator(ondemand::parser *_parser) n
2929
logger::log_headers();
3030
}
3131

32+
// GCC 7 warns when the first line of this function is inlined away into oblivion due to the caller
33+
// relating depth and parent_depth, which is a desired effect. The warning does not show up if the
34+
// skip_child() function is not marked inline).
35+
SIMDJSON_PUSH_DISABLE_WARNINGS
36+
SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
3237
simdjson_warn_unused simdjson_really_inline error_code json_iterator::skip_child(depth_t parent_depth) noexcept {
3338
if (depth() <= parent_depth) { return SUCCESS; }
3439

@@ -90,6 +95,8 @@ simdjson_warn_unused simdjson_really_inline error_code json_iterator::skip_child
9095
return report_error(TAPE_ERROR, "not enough close braces");
9196
}
9297

98+
SIMDJSON_POP_DISABLE_WARNINGS
99+
93100
simdjson_really_inline bool json_iterator::at_root() const noexcept {
94101
return token.checkpoint() == root_checkpoint();
95102
}

tests/ondemand/ondemand_basictests.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ namespace dom_api_tests {
12151215
ASSERT_ERROR( object["d"], NO_SUCH_FIELD );
12161216
return true;
12171217
}));
1218-
SUBTEST("ondemand::value", test_ondemand_doc(json, [&](auto doc_result) {
1218+
SUBTEST("simdjson_result<ondemand::value>", test_ondemand_doc(json, [&](auto doc_result) {
12191219
simdjson_result<ondemand::value> object = doc_result["outer"];
12201220
ASSERT_EQUAL( object["a"].get_uint64().first, 1 );
12211221
ASSERT_EQUAL( object["b"].get_uint64().first, 2 );
@@ -1690,7 +1690,7 @@ namespace ordering_tests {
16901690
}
16911691
return (x == 1.1) && (y == 2.2) && (z == 3.3);
16921692
}
1693-
#endif
1693+
#endif // SIMDJSON_EXCEPTIONS
16941694

16951695
bool run() {
16961696
return
@@ -1725,6 +1725,7 @@ namespace twitter_tests {
17251725
}));
17261726
TEST_SUCCEED();
17271727
}
1728+
17281729
#if SIMDJSON_EXCEPTIONS
17291730
bool twitter_example() {
17301731
TEST_START();
@@ -1746,7 +1747,7 @@ namespace twitter_tests {
17461747
}
17471748
TEST_SUCCEED();
17481749
}
1749-
#endif
1750+
#endif // SIMDJSON_EXCEPTIONS
17501751

17511752
bool twitter_default_profile() {
17521753
TEST_START();
@@ -1785,11 +1786,21 @@ namespace twitter_tests {
17851786
auto media = tweet["entities"]["media"];
17861787
if (!media.error()) {
17871788
for (auto image : media) {
1789+
uint64_t id_val;
1790+
std::string_view id_string;
1791+
ASSERT_SUCCESS( image["id"].get(id_val) );
1792+
ASSERT_SUCCESS( image["id_str"].get(id_string) );
1793+
std::cout << "id = " << id_val << std::endl;
1794+
std::cout << "id_string = " << id_string << std::endl;
1795+
17881796
for (auto size : image["sizes"].get_object()) {
1789-
auto size_value = size.value().get_object();
1797+
std::string_view size_key;
1798+
ASSERT_SUCCESS( size.unescaped_key().get(size_key) );
1799+
std::cout << "Type of image size = " << size_key << std::endl;
1800+
17901801
uint64_t width, height;
1791-
ASSERT_SUCCESS( size_value["w"].get(width) );
1792-
ASSERT_SUCCESS( size_value["h"].get(height) );
1802+
ASSERT_SUCCESS( size.value()["w"].get(width) );
1803+
ASSERT_SUCCESS( size.value()["h"].get(height) );
17931804
image_sizes.insert(make_pair(width, height));
17941805
}
17951806
}
@@ -1836,6 +1847,14 @@ namespace twitter_tests {
18361847
TEST_SUCCEED();
18371848
}
18381849

1850+
/*
1851+
* Fun fact: id and id_str can differ:
1852+
* 505866668485386240 and 505866668485386241.
1853+
* Presumably, it is because doubles are used
1854+
* at some point in the process and the number
1855+
* 505866668485386241 cannot be represented as a double.
1856+
* (not our fault)
1857+
*/
18391858
bool twitter_image_sizes_exception() {
18401859
TEST_START();
18411860
padded_string json = padded_string::load(TWITTER_JSON);
@@ -1845,30 +1864,13 @@ namespace twitter_tests {
18451864
for (auto tweet : doc_result["statuses"]) {
18461865
auto media = tweet["entities"]["media"];
18471866
if (!media.error()) {
1848-
for (ondemand::object image : media) {
1849-
/**
1850-
* Fun fact: id and id_str can differ:
1851-
* 505866668485386240 and 505866668485386241.
1852-
* Presumably, it is because doubles are used
1853-
* at some point in the process and the number
1854-
* 505866668485386241 cannot be represented as a double.
1855-
* (not our fault)
1856-
*/
1857-
uint64_t id_val = image["id"];
1858-
std::cout << "id = " << id_val << std::endl;
1859-
std::string_view id_string = image["id_str"];
1860-
std::cout << "id_string = " << id_string << std::endl;
1867+
for (auto image : media) {
1868+
std::cout << "id = " << uint64_t(image["id"]) << std::endl;
1869+
std::cout << "id_string = " << std::string_view(image["id_str"]) << std::endl;
18611870
for (auto size : image["sizes"].get_object()) {
1862-
/**
1863-
* We want to know the key that describes the size.
1864-
*/
1865-
std::string_view raw_size_key_v = size.unescaped_key();
1866-
std::cout << "Type of image size = " << raw_size_key_v << std::endl;
1867-
ondemand::object size_value = size.value();
1868-
int64_t width = size_value["w"];
1869-
int64_t height = size_value["h"];
1870-
std::cout << width << " x " << height << std::endl;
1871-
image_sizes.insert(make_pair(width, height));
1871+
std::cout << "Type of image size = " << std::string_view(size.unescaped_key()) << std::endl;
1872+
// NOTE: the uint64_t is required so that each value is actually parsed before the pair is created
1873+
image_sizes.insert(make_pair<uint64_t,uint64_t>(size.value()["w"], size.value()["h"]));
18721874
}
18731875
}
18741876
}
@@ -1879,7 +1881,7 @@ namespace twitter_tests {
18791881
TEST_SUCCEED();
18801882
}
18811883

1882-
#endif
1884+
#endif // SIMDJSON_EXCEPTIONS
18831885

18841886
bool run() {
18851887
return

0 commit comments

Comments
 (0)