This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/52985] New: Postincrement not applied after indexing ternary array expression
- From: "will at benfold dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 14 Apr 2012 11:00:41 +0000
- Subject: [Bug middle-end/52985] New: Postincrement not applied after indexing ternary array expression
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52985
Bug #: 52985
Summary: Postincrement not applied after indexing ternary array
expression
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: will@benfold.com
Created attachment 27156
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27156
Preprocessed source
[Component=middle-end was a guess, apologies if it's wrong.]
The code below prints an infinite series of zeros, as if the iterator is never
incremented.
The problem goes away if:
* the ternary expression is replaced by either tableA or tableB
* 'flag' is set to true
* the iterator increment is performed in a separate statement
* the vector and iterators are replaced with an array and (int *)
* tableA and tableB are replaced by vectors.
If the result of the array indexing is actually used, e.g. printed to cerr,
then results are the same at -O1 and above, but I see a segfault with -O0.
----------------------------------------------------------------
#include <iostream>
#include <vector>
int main (int argc, char *argv[])
{
std::vector<int> v(1);
int tableA[] = { 0 };
int tableB[] = { 0 };
bool flag = false;
for (std::vector<int>::const_iterator it = v.begin(); it != v.end();)
{
(flag ? tableA : tableB)[*it++];
std::cerr << (it - v.begin()) << "\n";
}
return 0;
}