From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2620 invoked by alias); 19 May 2005 21:20:31 -0000 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 Received: (qmail 2593 invoked by uid 48); 19 May 2005 21:20:24 -0000 Date: Thu, 19 May 2005 21:20:00 -0000 From: "igodard at pacbell dot net" To: gcc-bugs@gcc.gnu.org Message-ID: <20050519212022.21672.igodard@pacbell.net> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/21672] New: Loses temporary in complex expression X-Bugzilla-Reason: CC X-SW-Source: 2005-05/txt/msg02812.txt.bz2 List-Id: The attached source (and compiler output) produces the "testBitset" executable, which when run (no command line arguments) prints to std::cerr: ~/ootbc/common/test/src$ testBitset p is: bitset{a, c, e, g, k} q is: bitset{b:c, h, j:k} r is: bitset{a:c, e, g:h, j:k} but (p|q) is: bitset{d, f, h, j:k} "bitset" is a class that is similar to std::bitset except that it has one bit for each member of the enumeration that is a template argument to bitset. It is built on top of std::bitset and all bitset operations ultimately reflect to std::bitset. Stream operator<< is overloaded to display bitsets as shown above. Bitset defines operator| to produce a new bitset (of the same type) that is the bitwise "or" of the two arguments; this reflects ultimately to std::bitset::operator|=. The test case "main" contains "bitset r = (p|q);", where "p|q" produces a temporary that is immediately used to initialize r. When printed out by "std::cerr << r" this prints the correct value for the result of the "|" operation. However, if the "|" result is not stored into a variable but instead the temporary is passed directly to the streaming operator<< by "std::cerr << (p|q)" then the printed value is garbage. Exploration with the debugger shows that the temporary is being overwritten. The temporary should live to the end of the largest surrounding expression, which is the whole print statement, but it is not. -- Summary: Loses temporary in complex expression Product: gcc Version: 3.4.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: igodard at pacbell dot net CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21672