On 10/15/19 1:04 PM, Jakub Jelinek wrote:
Hi!

The following patch implements P1073R3, i.e. consteval, except that
virtual consteval is not supported (I think support for that would need to
include the consteval virtual methods at the end of the binfo structures
after all non-consteval virtual methods, but make sure we don't actually
emit those in the actual virtual tables etc.).

Perhaps we should bypass the existing virtual function call mechanism for consteval, and instead find the complete object directly and call non-virtually.

Unlike the previous implementation, this doesn't invoke consteval function
already during parsing, but later on, so there aren't issues with say
consteval constructors or consteval in default arguments.

Right, we can't immediately evaluate a class prvalue before we know what object it's initializing.

Initially I thought the best spot to do that would be during cp_fold, but
that isn't called e.g. on template function bodies before instantiation,
or on the expressions from unevaluated contexts, so I had to add a function
to walk trees and evaluate consteval function calls found in there.
Furthermore, cp_fold isn't called just during cp_fold_function, but also
during fold_for_warn etc., so some consteval functions might be evaluated
multiple times, which can be a problem that if there are errors, they might
be emitted multiple times.

I agree that cp_fold isn't the right place, since it does lowering for GCC internals, and consteval expansion is part of the language semantics. So it should happen before constexpr body saving, as in your patch.

It seems like we want a finish_full_expression, and do consteval folding there (and not from finish_function).

Jason

Reply via email to