Bug 26820 - g++ compiler: incorrect handling of reference parameters
Summary: g++ compiler: incorrect handling of reference parameters
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-23 06:25 UTC by ramiller
Modified: 2006-03-23 16:45 UTC (History)
46 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Source code from which compiler bug was determined (469 bytes, application/octet-stream)
2006-03-23 06:29 UTC, ramiller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ramiller 2006-03-23 06:25:12 UTC
Results of gcc -v -save-temps all-your-options source-file: 

gcc -v -save-temps all-your-options SampleExam1.cpp 
gcc: all-your-options: No such file or directory
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-54)
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GNUC_RH_RELEASE__=54 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ SampleExam1.cpp SampleExam1.ii
GNU CPP version 3.2.3 20030502 (Red Hat Linux 3.2.3-54) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/3.2.3
 /usr/include/c++/3.2.3/i386-redhat-linux
 /usr/include/c++/3.2.3/backward
 /usr/local/include
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/cc1plus -fpreprocessed SampleExam1.ii -quiet -dumpbase SampleExam1.cpp -version -o SampleExam1.s
GNU CPP version 3.2.3 20030502 (Red Hat Linux 3.2.3-54) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.3 20030502 (Red Hat Linux 3.2.3-54) (i386-redhat-linux)
        compiled by GNU C version 3.2.3 20030502 (Red Hat Linux 3.2.3-54).
 as -V -Qy -o SampleExam1.o SampleExam1.s
GNU assembler version 2.14.90.0.4 (i386-redhat-linux) using BFD version 2.14.90.0.4 20030523

I cannot figure out how to attach the source file here, but if you need it, please let me know.

Suppose a program contains the function 
double f1(double x_par, double y_par, double& z_par) 
{
// I have simplified the function operation here to avoid writing too many 
// unnecessary lines of code.

x_par = 3;
y_par = 1;
z_par = x_par + y_par;
return(z_par);
}

In main, I have the code:
double x = 8, y = 3, z = 1;
cout << f(x, y, z) << " " << x << y << z << endl;
cout << x << y << z << endl;

Given that z is a reference parameter, we would expect the output
4 834
834

but the actual output is
4 831
834

For some reason, the compiler is not recognizing the change to the reference argument in that first line of code.

Thank you for your time.
Comment 1 ramiller 2006-03-23 06:29:12 UTC
Created attachment 11102 [details]
Source code from which compiler bug was determined

I figured out how to attach the source code...
Comment 2 Andrew Pinski 2006-03-23 06:30:09 UTC
This is not a bug, you are misunderstanding what order stuff gets evaluated in the following expression:
cout << f(x, y, z) << " " << x << y << z << endl;


The C++ standard leaves the order of evaluating of f(x,y,z), the load of x, y, and z all up to the compiler and allows that order to be different at different level of optimizations also.

This is a dup of bug 11751.

*** This bug has been marked as a duplicate of 11751 ***

*** This bug has been marked as a duplicate of 11751 ***