This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: sequence point across assignment
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Anthony Shipman <als at iinet dot net dot au>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 12 Nov 2015 08:44:25 +0000
- Subject: Re: sequence point across assignment
- Authentication-results: sourceware.org; auth=none
- References: <1447288393 dot 18694 dot 16 dot camel at iinet dot net dot au>
On 12 November 2015 at 00:33, Anthony Shipman wrote:
> I had some code:
>
> states_[ix].next_ = compileStep(vec);
>
> The compileStep() function pushed something onto states_
> which caused its internal memory to be reallocated. As a result
> the returned value was copied to the wrong place. It appears
> that the left hand side is reduced to an address before the
> call is made.
>
> The compiler is g++ (SUSE Linux) 4.8.3 with options
> g++ -g -O0 -Wall -m64 -std=gnu++11 -fpic
>
> Have I strayed into undefined behaviour or is the compiler
> being silly? (Might this a consequence of the return value
> optimisation)?
>
(This question has nothing to do with libstdc++ so would be more
appropriate on gcc-help or a general C++ forum not specific to GCC).
THis has nothing to do with RVO.
The evaluation of the LHS and RHS of the assignment are
indeterminately sequenced, meaning that they do not overlap but it is
unspecified which happens first. You need to modify the code to ensure
the function call happens before evaluation of states_[ix].