This bug was found with the following command-line option:

g++ -I ../../Headers -g -o Runtime0 Runtime0.cpp

It has appeared with all variations of the command-line that I have tried.

I'm building a fairly complex (all right, maybe a little insane) c++
template metaprogram to do efficient probabilistic inference. As a
part of that program, I am building expression classes to represent
intermediate calculations, preventing the overhead and extra
computation associated with temporary variables. So, for example,
multiplying three probabilistic potentials Pa, Pb, Pc is done by
creating an Expression<Expression<Pa, Multiply, Pb>, Multiply, Pc>.

The expression syntax that I have, while not robust enough to be a
general solution, correctly handles the cases that I need it to, as
verified by my unit tests. pabc = pa*pb*pc evaluates correctly when
written into a unit test.

But in order for this to be useful, I need the metaprogram to generate
the multiplication expression, and when I do so, I do *not* get the
correct results. I have run this code against gcc401, gcc43, and the
intel compiler, and only the intel compiler gets it right.

I have traced the incorrect results to one line of my code. At some
point, I have the constructor:

Expression(const Lhs & lhs, const Rhs & rhs) : _potentials(rhs,
lhs._potentials) {}

Notice that I swap rhs and lhs in the _potentials() initiator, for
proper evaluation ordering. When I look at this line in the debugger,
I see the correct types. 

But when I step into the _potentials constructor:

PotentialContainer(const ThisPotential & p, const ImportBase & others)
        : Base(others), _potential(p) {}

the argument "p" has the address of the "lhs" variable from the
preceding constructor, and "others" has the address of the "rhs"
variable. Furthermore, the types of the arguments are correct,
resulting in the "lhs" argument being treated as if it was a
ThisPotential type, and "rhs" being treated as an ImportBase, which
results in data being overwritten.

As per the gcc bug reporting instructions, I've included an
intermediate file (Runtime0.ii) for a debug build (or rather, I intend to...
where is the upload option in bugzilla?). I've tested on multiple
platforms and with several different argument lists, including fully
optimized, and no version of gcc/g++ that I have tried has handled this case
correctly. (Again, the intel compiler *does* work.)

The Expression() constructor in question is on line 20555 of the
Runtime0.ii file that I have enclosed.

Sadly, I haven't been able to find a simpler test case. Nor have I
found any workarounds.


-- 
           Summary: Initializer incorrectly reordering arguments
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jwbates at mac dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40036

Reply via email to