[3.4 PATCH] PR c++/20995: Type-unsafe trees for templates

Roger Sayle roger@eyesopen.com
Mon Apr 25 02:17:00 GMT 2005


On Sun, 24 Apr 2005, Mark Mitchell wrote:
> The bodies of C++ templates are not valid GENERIC, nor are they meant to
> be.  It is not until template instantiation that these bodies look like
> normal code.


As a follow-up to my previous message, I've been retrospectively
working out where my misunderstanding stems from.


One confusing piece of evidence has been experiments by myself,
Kazu and Andrew Pinskia where we've placed asserts in the function
build2_stat (and others), to confirm that expressions are never
constructed with mismatched types.  By this measure, the g++
front-end *never* creates a mismatched binary expression.

The explanation...  The g++ front-end doesn't use the normal tree
construction machinery to build it's mismatched trees!  All of the
invalid trees are allocated via the function build_min_non_dep in
cp/tree.c!  This calls make_node and then sets all of the operands
explicitly itself.  Invisible to usual assertion checking.

Clearly, my rationalization was that a front-end that never creates
mismatched trees, can't intentionlly be working with/storing/manipulating
or more importantly folding mismatched trees.


More confusing is that g++ correctly constructs a valid tree via the
buildN APIs for every invalid one it constructs privately.  It just
throws the type-safe folded tree node away.  Even the number of calls
to buildN and fold look reasonable!

I'm sure in hindsight, I can probably explain away all of the evidence
that's led me to the wrong conclussion.

Roger
--



More information about the Gcc-patches mailing list