public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21672] New: Loses temporary in complex expression
@ 2005-05-19 21:20 igodard at pacbell dot net
  2005-05-19 21:22 ` [Bug c++/21672] " igodard at pacbell dot net
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: igodard at pacbell dot net @ 2005-05-19 21:20 UTC (permalink / raw)
  To: gcc-bugs

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>{a, c, e, g, k}
q is: bitset<A>{b:c, h, j:k}
r is: bitset<A>{a:c, e, g:h, j:k}
but (p|q) is: bitset<A>{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<A> 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


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2005-05-20  0:15 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-19 21:20 [Bug c++/21672] New: Loses temporary in complex expression igodard at pacbell dot net
2005-05-19 21:22 ` [Bug c++/21672] " igodard at pacbell dot net
2005-05-19 21:22 ` igodard at pacbell dot net
2005-05-19 22:56 ` pinskia at gcc dot gnu dot org
2005-05-19 23:12 ` igodard at pacbell dot net
2005-05-19 23:19 ` pinskia at gcc dot gnu dot org
2005-05-19 23:21 ` pinskia at gcc dot gnu dot org
2005-05-19 23:27 ` gdr at integrable-solutions dot net
2005-05-19 23:31 ` gdr at integrable-solutions dot net
2005-05-19 23:35 ` gdr at integrable-solutions dot net
2005-05-19 23:40 ` pinskia at gcc dot gnu dot org
2005-05-19 23:42 ` igodard at pacbell dot net
2005-05-19 23:42 ` pinskia at gcc dot gnu dot org
2005-05-19 23:46 ` pinskia at gcc dot gnu dot org
2005-05-19 23:54 ` igodard at pacbell dot net
2005-05-20  0:12 ` gdr at integrable-solutions dot net
2005-05-20  0:15 ` gdr at integrable-solutions dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).