From a665872e881920e8020a513340d2427b88a55bd6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 24 Feb 2017 15:00:47 -0500 Subject: add compile error for ignoring return value also introduce the _ identifier which you can assign to to discard a return value closes #219 --- src/analyze.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 6b864a7947..842ddbdf48 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3091,6 +3091,9 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { hash_val += 4048518294; hash_val += hash_size(const_val->data.x_ptr.data.hard_coded_addr.addr); return hash_val; + case ConstPtrSpecialDiscard: + hash_val += 2010123162; + return hash_val; } zig_unreachable(); } @@ -3601,6 +3604,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { if (a->data.x_ptr.data.hard_coded_addr.addr != b->data.x_ptr.data.hard_coded_addr.addr) return false; return true; + case ConstPtrSpecialDiscard: + return true; } zig_unreachable(); case TypeTableEntryIdArray: @@ -3785,6 +3790,9 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&canon_type->data.pointer.child_type->name), const_val->data.x_ptr.data.hard_coded_addr.addr); return; + case ConstPtrSpecialDiscard: + buf_append_str(buf, "&_"); + return; } zig_unreachable(); case TypeTableEntryIdFn: -- cgit v1.2.3