Skip to content

Commit d086268

Browse files
authored
Merge pull request #80 from r-spatial/fix-nested-anon
Fix nested anon type/union warning
2 parents 514a5d4 + cb918cb commit d086268

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

R/s2-xptr.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ validate_s2_xptr <- function(x) {
5454

5555
#' @export
5656
rep.s2_xptr <- function(x, ...) {
57-
new_s2_xptr(NextMethod(), class(x))
57+
if (length(x) == 0) {
58+
new_s2_xptr(list(), class(x))
59+
} else {
60+
new_s2_xptr(NextMethod(), class(x))
61+
}
5862
}
5963

6064
#' @method rep_len s2_xptr

data-raw/update-s2.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ print_next <- function() {
102102
"Replace calls to log(<int literal>), sqrt(<int literal>), and ldexp(<int literal>, ...) ",
103103
"with an explicit doouble (e.g., sqrt(3) -> sqrt(3.0) to fix build errors on CRAN Solaris"
104104
)
105+
cli::cat_bullet(
106+
"Ensure the code compiles on clang with -Wnested-anon-types. ",
107+
"These errors can be fixed by declaring the anonymous types just above the union. ",
108+
"(e.g., encoded_s2point_vector.h:91)"
109+
)
110+
105111
cli::cat_bullet("Replace `abort()` with `cpp_compat_abort()`")
106112
cli::cat_bullet("Replace `cerr`/`cout` with `cpp_compat_cerr`/`cpp_compat_cout`")
107113
cli::cat_bullet("Replace `srandom()` with `cpp_compat_srandom()`")

inst/include/s2/encoded_s2point_vector.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,35 @@ class EncodedS2PointVector {
9090
// TODO(ericv): Once additional formats have been implemented, consider
9191
// using std::variant<> instead. It's unclear whether this would have
9292
// better or worse performance than the current approach.
93+
94+
// dd: These structs are anonymous in the upstream S2 code; however,
95+
// this generates CMD-check failure due to the [-Wnested-anon-types]
96+
// (anonymous types declared in an anonymous union are an extension)
97+
// The approach here just names the types.
98+
struct CellIDStruct {
99+
EncodedStringVector blocks;
100+
uint64 base;
101+
uint8 level;
102+
bool have_exceptions;
103+
104+
// TODO(ericv): Use std::atomic_flag to cache the last point decoded in
105+
// a thread-safe way. This reduces benchmark times for actual polygon
106+
// operations (e.g. S2ClosestEdgeQuery) by about 15%.
107+
};
108+
109+
struct UncompressedStruct {
110+
const S2Point* points;
111+
};
112+
93113
enum Format : uint8 {
94114
UNCOMPRESSED = 0,
95115
CELL_IDS = 1,
96116
};
97117
Format format_;
98118
uint32 size_;
99119
union {
100-
struct {
101-
const S2Point* points;
102-
} uncompressed_;
103-
struct {
104-
EncodedStringVector blocks;
105-
uint64 base;
106-
uint8 level;
107-
bool have_exceptions;
108-
109-
// TODO(ericv): Use std::atomic_flag to cache the last point decoded in
110-
// a thread-safe way. This reduces benchmark times for actual polygon
111-
// operations (e.g. S2ClosestEdgeQuery) by about 15%.
112-
} cell_ids_;
120+
struct UncompressedStruct uncompressed_;
121+
struct CellIDStruct cell_ids_;
113122
};
114123
};
115124

tests/testthat/test-s2-xptr.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ test_that("s2_xptr validation works", {
2020
})
2121

2222
test_that("s2_xptr subsetting and concatenation work", {
23+
expect_length(rep(new_s2_xptr(list()), 10), 0)
24+
2325
xptr <- new_s2_xptr(list(NULL, NULL))
2426
expect_identical(xptr[1], new_s2_xptr(list(NULL)))
2527
expect_identical(xptr[[1]], xptr[1])

0 commit comments

Comments
 (0)