Closed Daniel-Cortez closed 3 years ago
It seems the reason of this bug is that functions user_inc()
and user_dec()
(file sc3.c
) are empty:
/* These two functions are defined because the functions inc() and dec() in
* SC4.C have a different prototype than the other code generation functions.
* The arrays for user-defined functions use the function pointers for
* identifying what kind of operation is requested; these functions must all
* have the same prototype. As inc() and dec() are special cases already, it
* is simplest to add two "do-nothing" functions.
*/
static void user_inc(void) {}
static void user_dec(void) {}
, so in Release
and MinSizeRel
modes they simply get merged into one function, and because of this, instead of operator --(Tag:)
the compiler tries to find and call operator ++(Tag:)
.
Simply adding extra code into either of those functions, e.g.
static void user_inc(void) {}
static void user_dec(void) { dec(NULL); }
prevents this optimization and thus fixes the problem, but I'm pretty sure there might be a better solution for this, preferable the one that doesn't involve adding any extra code at all.
That's not good... Hopefully there's a solution that doesn't rely on trying to avoid compiler optimisations, because that's a battle you'll never truly win - it'll undoubtedly pop up again in some other place some other time.
Fixed in #617.
Issue description:
When using operator
--
on a tagged value with overloaded operators++
and--
, the compiler generates code for calling operator++
instead of--
.Minimal complete verifiable example (MCVE):
When using the
-a
option, the following listing for functionmain()
is generated:As can be seen here, the compiler generates code for calling operator
++
instead of--
for both prefix and postfix-form decrement.Workspace Information:
Release
orMinSizeRel
mode; the builds from the Releases page aren't affected), 3.2.3664