From: René Scharfe Date: Tue, 31 Jan 2017 21:03:01 GMT Subject: Re: [PATCH 1/5] add SWAP macro Message-ID: <8e94756a-c3a5-9b81-268d-d0f36876f710@web.de> In-Reply-To: <20170130222157.GC35626@google.com> Am 30.01.2017 um 23:21 schrieb Brandon Williams: > On 01/30, René Scharfe wrote: >> Am 30.01.2017 um 22:03 schrieb Johannes Schindelin: >>> It is curious, though, that an >>> expression like "sizeof(a++)" would not be rejected. >> >> Clang normally warns about something like this ("warning: expression >> with side effects has no effect in an unevaluated context >> [-Wunevaluated-expression]"), but not if the code is part of a >> macro. I don't know if that's intended, but it sure is helpful in >> the case of SWAP. >> >>> Further, what would SWAP(a++, b) do? Swap a and b, and *then* increment a? >> >> That might be a valid expectation, but GCC says "error: lvalue >> required as unary '&' operand" and clang puts it "error: cannot take >> the address of an rvalue of type". >> >> René > > Perhaps we could disallow a side-effect operator in the macro. By > disallow I mean place a comment at the definition to the macro and > hopefully catch something like that in code-review. We have the same > issue with the `ALLOC_GROW()` macro. SWAP(a++, ...) is caught by the compiler, SWAP(*a++, ...) works fine. Technically that should be enough. :) A comment wouldn't hurt, of course. René