From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17458 invoked by alias); 26 Jan 2006 17:29:41 -0000 Received: (qmail 17441 invoked by uid 48); 26 Jan 2006 17:29:37 -0000 Date: Thu, 26 Jan 2006 17:29:00 -0000 Subject: [Bug c++/25979] New: incorrect codegen for conditional X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "hhinnant at apple dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-01/txt/msg02876.txt.bz2 List-Id: I'm not positive whether or not this is a duplicate of 25895. I figured I'd better enter it just in case it wasn't. Test case: #include struct A { A() : data1_(0), data2_(0) {} A(int i, int j) : data1_(i), data2_(j) {} A operator+(int); friend A operator+(int, const A&); ~A() {} //private: int data1_; int data2_; }; extern bool x; void display(const A& x) { printf("%d %d\n", x.data1_, x.data2_); } int main() { A a1(1,2); a1 = (x ? a1 + 3 : 3 + a1); display(a1); } bool x = false; A A::operator+(int i) { A a; a = *this; a.data2_ = i; return a; } A operator+(int i, const A& x) { A a; a = x; a.data1_ = i; return a; } Output: 3 0 Expected output: 3 2 The gimple tree (-fdump-tree-gimple) is showing statements like: operator+ (&a1, 3, &a1) [return slot addr]; which shoud instead be: operator+ (temp, 3, &a1) [return slot addr]; ... a1 = temp; The bad codegen is sensitive to the presence or absence of special member functions. For example if you comment out ~A(), you get the expected output. -- Summary: incorrect codegen for conditional Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hhinnant at apple dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25979