[cfe-dev] integer constant expression oh my!

Doug Gregor doug.gregor at gmail.com
Mon Nov 17 09:57:06 PST 2008


On Mon, Nov 17, 2008 at 12:47 PM, Sebastian Redl
<sebastian.redl at getdesigned.at> wrote:
> Chris Lattner wrote:
>> I wrote up some thoughts about how I think that constants should
>> eventually be handled in clang:
>> http://clang.llvm.org/docs/InternalsManual.html#Constants
>>
>> The goal is for Expr::isConstantExpr and many other things to
>> eventually go away, and only have one piece of code that does the
>> constant folding tree walk.  Before we get too far along this path, I
>> thought it would be good to see if this makes sense to others... so,
>> what say you all? :)
>>
> One thing to be aware of in the design is that we'll very likely want
> this to handle support for the C++0x constexpr feature. To sum it up for
> those who're not following the new standard: Simple functions can be
> marked constexpr. The compiler is required to evaluate them at compile
> time if all arguments are themselves constant expressions, and the
> result is again a constant expression. Objects constructed with a
> constexpr constructor have the status of object literals, and an access
> to their members is again a constant expression. There's also constexpr
> user-defined literal converters to consider, but they mostly act like
> ordinary constexpr functions in this regard.

This also means that one can end up instantiating a template as part
of the evaluation of an integral constant expression (if that template
is a constexpr function template). I think the only real effect this
has on the design is that the ICE checking and expression evaluation
code will need to move from AST into Sema.

  - Doug



More information about the cfe-dev mailing list