From d11fe077ad6e1e9fc3de99380e6cca01ca630c4d Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Tue, 30 May 2017 15:04:50 -0700 Subject: [PATCH] C++Backend return_second() impl should avoid warnings Emitting as (a, b) using the comma operator does what we want, but triggers the "unused-value" warning under common GCC settings. Adding a templated helper function to explicitly evaluate-but-ignore the first arg allows us to avoid requiring consumers to disable warnings. --- src/CodeGen_C.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CodeGen_C.cpp b/src/CodeGen_C.cpp index 7c7d567e41af..0a360298f8b0 100644 --- a/src/CodeGen_C.cpp +++ b/src/CodeGen_C.cpp @@ -108,6 +108,12 @@ inline float float_from_bits(uint32_t bits) {return reinterpret template T max(T a, T b) {if (a > b) return a; return b;} template T min(T a, T b) {if (a < b) return a; return b;} +template +const B &return_second(const A &a, const B &b) { + (void) a; + return b; +} + namespace { class HalideFreeHelper { typedef void (*FreeFunction)(void *user_context, void *p); @@ -1042,7 +1048,7 @@ void CodeGen_C::visit(const Call *op) { internal_assert(op->args.size() == 2); string arg0 = print_expr(op->args[0]); string arg1 = print_expr(op->args[1]); - rhs << "(" << arg0 << ", " << arg1 << ")"; + rhs << "return_second(" << arg0 << ", " << arg1 << ")"; } else if (op->is_intrinsic(Call::if_then_else)) { internal_assert(op->args.size() == 3);