News for hackers. Stuff that matters.
Re:C++ std::move doesn't move anything: A deep dive into Val... by krona on Sunday January 11, 2026 @05:43AM (#46574366)
> So the standard library plays it safe: if your move constructor might throw (because you didn’t mark it noexcept), containers just copy everything instead. That “optimization” you thought you were getting? It’s not happening.

This is a bit of a footgun and clang-tidy has a check for it: performance-noexcept-move-constructor. However, I don't think it's enabled by default!

Re:C++ std::move doesn't move anything: A deep dive into Val... by juliangmp on Sunday January 11, 2026 @06:42AM (#46574801)
Most sensible Compiler flags aren't enabled by default... I keep a list of arguments for gcc to make things better, but even then you'll also wanna use a static analysis tool like clang-tidy
Re:C++ std::move doesn't move anything: A deep dive into Val... by teraro on Sunday January 11, 2026 @08:02AM (#46575389)
Would you mind sharing your list?
Re:C++ std::move doesn't move anything: A deep dive into Val... by juliangmp on Monday January 12, 2026 @07:02PM (#46595801)
Sure, I put quickly put them into a small markdown file. At my job we have a cmake interface target that handles these (along with some version checks and project specific stuff), but I can't publish that of course. I might put these into a cmake file at some point, not sure.

https://codeberg.org/JulianGmp/sane-args-cpp

Re:C++ std::move doesn't move anything: A deep dive into Val... by Fiveplus on Sunday January 11, 2026 @06:47AM (#46574833)
The reason performance-noexcept-move-constructor is not enabled by default is likely because blindly applying noexcept is dangerous if the underlying logic isn't actually exception-free. If you let clang-tidy slap noexcept on a move constructor that does end up throwing (perhaps because it calls into a legacy member or allocates memory internally), the runtime behavior changes from caught exception to std::terminate().
Re:C++ std::move doesn't move anything: A deep dive into Val... by immibis on Sunday January 11, 2026 @07:37AM (#46575219)
clang-tidy checks but doesn't change things for you.

Since you can also put noexcept(false) to indicate something throws exceptions and you didn't just forget to mark it noexcept, it's not a bad policy to say every move constructor should have a noexcept marker.

Re:C++ std::move doesn't move anything: A deep dive into Val... by phkahler on Sunday January 11, 2026 @07:22AM (#46575126)
Exceptions should never be enabled by default. We live in a 64bit world so allocations failing indicates some other problem.
Re:C++ std::move doesn't move anything: A deep dive into Val... by zbentley on Sunday January 11, 2026 @08:10AM (#46575439)
What does processor but width have to do with the likelihood of allocation failures?
Re:C++ std::move doesn't move anything: A deep dive into Val... by petcat on Sunday January 11, 2026 @08:55AM (#46575807)
640K ought to be enough for anybody!
Re:C++ std::move doesn't move anything: A deep dive into Val... by HarHarVeryFunny on Sunday January 11, 2026 @09:02AM (#46575851)
I think what he means is that on a 64-bit system you have a massive virtual address space (typically only 48-bit, but that's still 256TB), and since malloc allocates from virtual address space, not limited by physical memory, it is unlikely you will get a malloc failure (unless you are trying to allocate more than 256TB per process, maybe due to a memory leak).
Re:C++ std::move doesn't move anything: A deep dive into Val... by locknitpicker on Monday January 12, 2026 @02:31AM (#46585248)
> it is unlikely you will get a malloc failure

That assertion completely misses the point. The scenarios involving move constructors throwing exceptions involve objects being stuck in an inconsistent/zombie state. In fact, the whole point of a move constructors is to avoid having to allocate memory.

Re:C++ std::move doesn't move anything: A deep dive into Val... by zbentley on Tuesday January 13, 2026 @05:56PM (#46609577)
That's not true as generally as you might expect.

Folks might be using mmap with MAP_POPULATE; they might have overcommit turned off; they might be operating in an rlimit/cgroup (like most container runtimes/orchestrators configure) that limits memory; they might be on a system which doesn't have virtual memory (plenty such systems exist in 64-bit architectures); they might be using calloc on an OS that zeros pessimistically/early; and so on.

Re:C++ std::move doesn't move anything: A deep dive into Val... by usefulcat on Sunday January 11, 2026 @02:13PM (#46578796)
Exceptions can be used to indicate many kinds of errors, not just allocation failures.
Re:C++ std::move doesn't move anything: A deep dive into Val... by dbcpp on Sunday January 11, 2026 @09:30AM (#46576056)
I would argue performance-noexcept-move-constructor should always be on. Move constructors should almost always be noexcept since they typically just move pointers around and don't do allocations normally.
Re:C++ std::move doesn't move anything: A deep dive into Val... by jcelerier on Sunday January 11, 2026 @11:50AM (#46577305)
eh, depends. for instance think about a small_vector or small_string
Re:C++ std::move doesn't move anything: A deep dive into Val... by dbcpp on Sunday January 11, 2026 @11:55AM (#46577353)
True, in that case it should just inherit the noexcept status of the object it holds.
Re:C++ std::move doesn't move anything: A deep dive into Val... by HarHarVeryFunny on Sunday January 11, 2026 @10:14AM (#46576409)
The documentations seems to say that option only causes the compiler to issue a warning when move constructors are not marked noexcept - it doesn't override anything.

https://clang.llvm.org/extra/clang-tidy/checks/performance/n... constructor.html

Note that the way std::vector (and other STL containers) require noexcept move constructors for reallocation is by using template matching, and of course any other code might be doing this too, so having a compiler option that forced a constructor (or anything) to have a type signature different than the way it was declared would be a pretty dangerous thing to do since it'd be hard to know what the consequences would be.

Re:C++ std::move doesn't move anything: A deep dive into Val... by rfc3092 on Sunday January 11, 2026 @11:01AM (#46576841)
performance-noexcept-move-constructor is great but it also complains about move assignment operators, which are completely different beasts and are practically impossible to make noexcept if your destructors throw.
Re:C++ std::move doesn't move anything: A deep dive into Val... by dataflow on Sunday January 11, 2026 @12:13PM (#46577525)
If that's the issue you're facing, consider clang-query, e.g.: https://godbolt.org/z/bfG94qGan

  match cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isMoveConstructor(), unless(isNoThrow())).bind("throwing-move")))
You can put extra constraints on the caller if you'd like (e.g., isInStdNamespace()), though it's less trivial. Happy to help write something if you have a precise idea of what you want to match.
Re:C++ std::move doesn't move anything: A deep dive into Val... by beached_whale on Sunday January 11, 2026 @12:34PM (#46577691)
Throwing destructors will generally end in termination of the program if they are used as class members. Types like scope_exit are fine, but anywhere else will probably have noexcept(true) on it's destructor.
Re:C++ std::move doesn't move anything: A deep dive into Val... by beached_whale on Sunday January 11, 2026 @12:32PM (#46577678)
Throwing move is super weird too. I believe that it was a mistake to not treat user move like C++11 destructors and default to noexcept(true) on them. But it is what it is.

On the other hand, writing special member functions at all(move & copy constructor/assignment, destructor) is a smell for types that don't just manage the lifetime of an object(unique_ptr like things). People should not generally be writing them and being open to the mistake of getting noexcept wrong.

Re:C++ std::move doesn't move anything: A deep dive into Val... by locknitpicker on Monday January 12, 2026 @02:25AM (#46585205)
> Throwing move is super weird too. I believe that it was a mistake to not treat user move like C++11 destructors and default to noexcept(true) on them. But it is what it is.

I think you're missing a fair deal of insight into the issue.

The move semantics proposal documents this aspect in clear and unambiguous terms:

- Almost any class should be able to create a nothrow move assignment operator.

- a basic requirement is that a class must have a valid resource less state (i.e., remain in a valid state after having been moved)

- those that can't, shouldn't define move semantics.

Re:C++ std::move doesn't move anything: A deep dive into Val... by grogers on Sunday January 11, 2026 @01:11PM (#46578019)
If I'm not mistaken, all the pitfalls in the article have clang-tidy lints to catch
Re:C++ std::move doesn't move anything: A deep dive into Val... by jeffbee on Sunday January 11, 2026 @04:34PM (#46580391)
Nothing about clang-tidy is enabled by default, and getting it to run at all in realistic projects is quite a chore.