Skip to content

Crash in constant evaluation of explicit object member assignment operator #142835

@cor3ntin

Description

@cor3ntin
struct MoveMe {
  MoveMe& operator=(this MoveMe&, const MoveMe&) = default;
  constexpr MoveMe& operator=(this MoveMe& self, MoveMe&& other) {
    self.value = other.value;
    other.value = 0;
    return self;
  }
  int value = 4242;
};

struct S {
  S& operator=(this S&, const S&) = default;
  S& operator=(this S&, S&&) = default;

  MoveMe move_me;
};

constexpr bool f() {
  S s1{};
  S s2{};
  s2 = s1;
  return true;
}

static_assert(f());

clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ExprConstant.cpp:6656: bool HandleFunctionCall(clang::SourceLocation, const clang::FunctionDecl*, const {anonymous}::LValue*, const clang::Expr*, llvm::ArrayRef<const clang::Expr*>, {anonymous}::CallRef, const clang::Stmt*, {anonymous}::EvalInfo&, clang::APValue&, const {anonymous}::LValue*): Assertion This && (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())' failed.

https://compiler-explorer.com/z/1nxjPP5Yh

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions