Remix.run Logo
Fiveplus 11 hours ago

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().

HarHarVeryFunny 7 hours ago | parent | next [-]

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.

dbcpp 8 hours ago | parent | prev | next [-]

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.

8 hours ago | parent | next [-]
[deleted]
jcelerier 6 hours ago | parent | prev [-]

eh, depends. for instance think about a small_vector or small_string

dbcpp 6 hours ago | parent [-]

True, in that case it should just adopt the noexcept status of the object it holds.

immibis 10 hours ago | parent | prev | next [-]

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.

phkahler 10 hours ago | parent | prev [-]

Exceptions should never be enabled by default. We live in a 64bit world so allocations failing indicates some other problem.

zbentley 9 hours ago | parent | next [-]

What does processor but width have to do with the likelihood of allocation failures?

HarHarVeryFunny 8 hours ago | parent | next [-]

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).

petcat 9 hours ago | parent | prev [-]

640K ought to be enough for anybody!

usefulcat 3 hours ago | parent | prev [-]

Exceptions can be used to indicate many kinds of errors, not just allocation failures.