This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Start handling mutable record members
AbandonedPublic

Authored by tbaeder on Apr 5 2023, 8:19 AM.

Diff Detail

Event Timeline

tbaeder created this revision.Apr 5 2023, 8:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 8:19 AM
tbaeder requested review of this revision.Apr 5 2023, 8:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 8:19 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added a comment.May 2 2023, 9:20 AM

Two cases to consider: https://godbolt.org/z/ovofPExGK

namespace MutableFields {
  class Foo {
  public:
    constexpr Foo() : I(1) {}
    mutable int I; // ref-note {{declared here}}
  };


  constexpr int foo() {
    constexpr Foo F;  
    F.I = 12;
    return F.I;
  }
  static_assert(foo() == 12, "");
}

clang and gcc disagree on this one, I think clang is right not 100%.

and this one:

namespace MutableFields {
  class Foo {
  public:
    constexpr Foo() : I(1) {}
    mutable int I; // ref-note {{declared here}}
  };


  constexpr int foo() {
    constexpr Foo F;  // A
    F.I = 12;
    constexpr int x = F.I; // B
    return F.I;
  }
  static_assert(foo() == 12, "");
}
tbaeder updated this revision to Diff 519434.May 4 2023, 4:31 AM
tbaeder abandoned this revision.Jul 27 2023, 12:31 AM