Skip to content

Vec::operator[] use-after-move does not abort #254

Open
@nigeltao

Description

@nigeltao

PRINCIPLES.md says:

No use-after-move. All types abort if they are used after a move.

However:

TEST(Vec, UseAfterMoveAllowsCreatingBadPointer) {
  struct T {
    uint8_t pre_padding[0xBAD'0000];
    int field;
  };
  auto x = Vec<T>();
  auto y = std::move(x);
  int* bad_ptr = &x[0].field;  // Use-after-move but does not abort.
  printf("%p\n", bad_ptr);     // Prints "0xbad0000\n".
}

Is this Working As Intended?

Metadata

Metadata

Assignees

No one assigned

    Labels

    designDesign of the library systems as a whole, such as conceptssafetyMemory safety improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions