Re: Why std::vector requires noexcept move constructor?

Liste des GroupesRevenir à cl c++ 
Sujet : Re: Why std::vector requires noexcept move constructor?
De : eesnimi (at) *nospam* osa.pri.ee (Paavo Helde)
Groupes : comp.lang.c++
Date : 17. Jun 2025, 06:48:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102qvjp$26sqr$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 16.06.2025 21:50, Marcel Mueller wrote:

Maybe a move constructor w/o noexcept should be a warning, because it makes no much sense to throw within a move operation.
It is a warning C26439 in VS2022, albeit you need to call the special code analysis step instead of standard code compilation.
Analyze: Run Code analysis
Build started at 08:43...
1>------ Build started: Project: ConsoleTest2022, Configuration: Debug x64 ------
1>main.cpp
1>C:\Test\ConsoleTestVS2022\ConsoleTest2022\main.cpp(6,7): warning C4625: 'bar': copy constructor was implicitly defined as deleted
1>C:\Test\ConsoleTestVS2022\ConsoleTest2022\main.cpp(6,7): warning C4626: 'bar': assignment operator was implicitly defined as deleted
C:\Test\ConsoleTestVS2022\ConsoleTest2022\main.cpp(9): warning C26439: This kind of function should not throw. Declare it 'noexcept' (f.6).
1>Done building project "ConsoleTest2022.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 08:43 and took 01,440 seconds ==========
#include <iostream>
#include <string>
#include <vector>
class bar {
public:
bar() = default;
bar(bar&& b): s_(std::move(b.s_)) {}
private:
std::string s_;
};
int main() {
std::vector<bar> bars;
bars.push_back(bar());
}

Date Sujet#  Auteur
15 Jun 25 * Why std::vector requires noexcept move constructor?5Marcel Mueller
16 Jun 25 +* Re: Why std::vector requires noexcept move constructor?3Paavo Helde
16 Jun 25 i`* Re: Why std::vector requires noexcept move constructor?2Marcel Mueller
17 Jun 25 i `- Re: Why std::vector requires noexcept move constructor?1Paavo Helde
1 Jul18:13 `- Re: Why std::vector requires noexcept move constructor?1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal