[clang] [clang] [NFC] Improve move-assign and move-constructor for NestedNameSpecifierLocBuilder (PR #180484)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 12 08:50:27 PST 2026


mizvekov wrote:

A move constructor and move assignment can be implemented in terms of swap roughly so I believe:

```
struct Foo {
  Foo(Foo&& Other) {
    operator=(std::move(Other));
  }
  
  Foo& operator=(Foo &&Other) {
    Foo T;
    swap(*this, T);
    swap(*this, Other);
    return *this;
  }
};
```

That also leaves the moved from object in an empty state.

The advantage is that a swap implementation is a simple memberwise swap, and the resource management is reused from the destructor.

In other contexts, outside of LLVM, this is also a simple way to implement these operations in an exception-safe manner.

https://github.com/llvm/llvm-project/pull/180484


More information about the cfe-commits mailing list