http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51712
--- Comment #7 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-26 11:59:30 UTC --- (In reply to comment #6) > On Tue, 17 Apr 2012, manu at gcc dot gnu.org wrote: > > > Unfortunately, I cannot see any way to know that FOO is a constant that > > comes > > from an enum. Joseph, is this possible to do in the C FE? > > The original types of expressions that came from enums are already tracked > for use of -Wc++-compat (checking if C code is compatible with stricter > C++ rules for enums). (This is what c-typeck.c:build_external_ref uses > the type pointer for: storing the original type of an enum.) So the > information is available in at least parts of the C front end. I see two ways to implement this: * Make build_binary_op take c_expr instead of trees. This will require adding c_expr to the C++ FE. For now, the C++ FE will just encapsulate the trees into c_expr before calling build_binary_op and nothing else. If the long-term goal is that C/C++ FEs track the original source code more faithfully, I think this is the right step. The use of c_expr should help to achieve this. * Pass 4 more arguments to build_binary_op, one for each c_expr and add a wrapper to avoid changing the interface for C++ FE. This restricts the changes to the C FE (and c-common.c) but it is really ugly. Joseph/Jason, what do you think?