Skip to content

Commit 7ab9733

Browse files
Fix unintentional macro shadowing in json.h (#8162)
json.h defines two lambdas with the same name [link](https://github.com/WebAssembly/binaryen/blob/c2e47d3bffdb66e237525da24d8c28f4b5402f20/src/support/json.h#L274-L283). From #8086, the calls in json.h are macro-expanded rather than using the lambdas defined there. This is coincidentally ok because they have the exact same definition, but results in an unused variable warning for the two lambdas. This happens in #8086 and not in main because that PR adds `#include "ir/memory-utils.h"` in wasm-interpreter.h which probably results in simple_ast.h being included before json.h which causes the shadowing. [Without this PR](https://gist.github.com/stevenfontanella/16ea5cc5144db625e5b6194706e3617d). With this PR, compilation succeeds.
1 parent c2e47d3 commit 7ab9733

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/emscripten-optimizer/simple_ast.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,15 @@ struct Value {
310310
}
311311

312312
char* parse(char* curr) {
313-
/* space, tab, linefeed/newline, or return */
314-
#define is_json_space(x) (x == 32 || x == 9 || x == 10 || x == 13)
315-
#define skip() \
316-
{ \
317-
while (*curr && is_json_space(*curr)) \
318-
curr++; \
319-
}
313+
/* space, tab, linefeed/newline, or return */
314+
constexpr auto is_json_space = [](char x) {
315+
return x == 32 || x == 9 || x == 10 || x == 13;
316+
};
317+
auto skip = [&curr, &is_json_space]() {
318+
while (*curr && is_json_space(*curr)) {
319+
curr++;
320+
}
321+
};
320322
skip();
321323
if (*curr == '"') {
322324
// String

0 commit comments

Comments
 (0)