Page MenuHomePhabricator

Initialize static const fields in the AST for expression evaluation
Needs ReviewPublic

Authored by jarin on Aug 11 2020, 3:25 AM.

Details

Reviewers
teemperor
shafik
Summary

This patch is for discussion.

Currently, the evaluator does not know about static const fields if
the code does not contain a definition (but only a declaration).

For example:

struct C { static const int f = 42; };
int main() {
  return C::f;  // Evaluating C::f does not work here!
}

This patch tries to fix that by initializing the varDecl of the static
field with the constant value. This works reasonably well when the
static member is only used as rvalue, but any lvalue usage still does
not work because the static member does not have a memory location.

To fix this properly, do we have to teach the materializer about the
static fields, too? What would be the best way to go about that?

Diff Detail

Event Timeline

jarin created this revision.Aug 11 2020, 3:25 AM
jarin requested review of this revision.Aug 11 2020, 3:25 AM

There is actually https://reviews.llvm.org/D81471 that makes this fully work, but it's still waiting on someone to review it :)