http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57693
Bug ID: 57693
Summary: The program logically failed in case of used int b +=
b++
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vlad94009277 at gmail dot com
Steps to reproduce:
1. Write the following source cod and compile it:
#include iostream
using namespace std;
int main(){
int d = 7;
int c = 7;
int b = c;
b += b++;
d += d++;
cout c = c endl;
cout d = d endl;
return 0;
}
2. Run the appropriate generated executable file.
Actual result:
It's printed:
c = 8
d = 15
Expected result:
It should be printed:
c = 15
d = 15
Please note that there are different assemble codes for used operators:
1) d += d++
movl -4(%rbp), %eax // Copies value of d to register %eax
addl %eax, %eax // Adds %eax to %eax, remembers the value in %eax
movl %eax, -4(%rbp) // Moves %eax to d (d = 14)
addl $1, -4(%rbp) // Increments the value of d (d = 15)
2) b += b++
movl -12(%rbp), %eax // Moves the value of b to %eax
movl -12(%rbp), %edx // Moves the value of b to %edx
leal (%rax,%rdx), %edx // Adds %rax to %rdx and stores result in %edx (%rax and
%rdx are equal to 7, so after this operation %edx is 14)
movl %edx, -12(%rbp) // Moves %edx to d (d = 14)
addl $1, %eax // Increments the value of %eax (%eax = 8).
movl %eax, -12(%rbp) // Moves %eax to d (d = 8)