noexcept

What does “see below” mean when used as a type or exception specification?

淺唱寂寞╮ 提交于 2019-12-01 06:37:32
Looking through the C++ standard ( current draft http://isocpp.org/files/papers/N3690.pdf , sec 20.8.3 is one such place) and through LLVM's libc++ headers, I've found "see below" used as a type and exception specification. It seems to be used when no type exists, but it seemed strange to use a 2 word phrase for that instead of some sort of valid identifier. Is it discussed somewhere in the standard or elsewhere? Why/how is it used? see below is simply a place holder for one of a few possible types which are always described in the following text. For example here: typedef see below element

“Default member initializer needed within definition of enclosing class outside of member functions” - is my code ill-formed?

╄→гoц情女王★ 提交于 2019-12-01 04:00:50
struct foo { struct bar { ~bar() {} // no error w/o this line }; bar *data = nullptr; // no error w/o this line foo() noexcept = default; // no error w/o this line }; Yes, I know, there is another question with exactly the same title, but a somewhat different problem (involving a noexcept operator and no nested type). The solution suggested there (replacing the constructor of foo with foo() noexcept {} ) changes the semantics and it not necessary here: here we have a better answer (hence the question is not a duplicate). compiler: Apple LLVM version 9.0.0 (clang-900.0.37) , full error message:

Are move constructors required to be noexcept?

放肆的年华 提交于 2019-11-30 21:55:45
问题 I've been reading some contradicting articles in regards whether move constructors/assignment is allowed to throw or not. Therefore I'd like to ask whether move constructors/assignments are allowed to throw in the final C++11 standard? 回答1: Are move constructors in general allowed to throw? Yes. Should they? No. In general, nothing you do within them should be anything that could throw. You shouldn't be allocating memory, calling other code, or anything like that. The only reason to write a

Constructor with by-value parameter & noexcept

自闭症网瘾萝莉.ら 提交于 2019-11-30 08:23:11
In this example code: explicit MyClass(std::wstring text) noexcept; Is the use of noexcept here correct? wstring can potentially throw on construction but does the throw happen before we are in the constructor or while we are in the constructor? EDIT: Suppose this can be generalised to any function taking a by-value parameter. The construction and destruction of function parameters happens in the context of the caller. So no, if the construction of text throws, that is not a violation of noexcept . Soon folks would comment and ask for a spec quote :) So I will give you 5.2.2p4 The

Noexcept and copy, move constructors

会有一股神秘感。 提交于 2019-11-30 06:56:35
Everywhere I look it seems to be the agreement that the standard library must call copy constructors instead of move constructors when the move constructor is noexcept(false). Now I do not understand why this is the case. And futher more Visual Studio VC v140 and gcc v 4.9.2 seems to do this differently. I do not understand why noexcept this is a concern of e.g. vector. I mean how should vector::resize() be able to give strong exception guarantee if T does not. As I see it the exception level of vector will be dependend on T. Regardless if copy or move is used. I understand noexcept to solely

Static analysis of noexcept “violations” in C++

一曲冷凌霜 提交于 2019-11-30 06:43:17
I'm trying to write exception safe code. I find that using C++11's noexcept specifier makes this goal a whole lot more achievable. The general idea, of course, is that a function should be marked as 'noexcept' if, and only if all the functions that it calls are also marked as 'noexcept'. The problem is that in a large code base, where patches from different people are often merged together, it is hard to ensure that this consistency is maintained. So I would like to be able to run a static analysis that could list all places where a function that is marked 'nothrow' calls a function that is

noexcept depend on noexcept of a member function

与世无争的帅哥 提交于 2019-11-30 04:02:27
问题 Consider: class test { private: int n; int impl () const noexcept { return n; } public: test () = delete; test (int n) noexcept : n(n) { } int get () const noexcept(noexcept(impl())) { return impl(); } }; GCC says no: test.cpp:27:43: error: cannot call member function 'int test::impl() const' with out object int get () const noexcept(noexcept(impl())) { Similarly: test.cpp:27:38: error: invalid use of 'this' at top level int get () const noexcept(noexcept(this->impl())) { and test.cpp:31:58:

Passing null pointer to placement new

风流意气都作罢 提交于 2019-11-29 22:50:53
The default placement new operator is declared in 18.6 [support.dynamic] ¶1 with a non-throwing exception-specification: void* operator new (std::size_t size, void* ptr) noexcept; This function does nothing except return ptr; so it is reasonable for it to be noexcept , however according to 5.3.4 [expr.new] ¶15 this means that the compiler must check it doesn't return null before invoking the object's constructor: -15- [ Note: unless an allocation function is declared with a non-throwing exception-specification (15.4), it indicates failure to allocate storage by throwing a std::bad_alloc

Constructor with by-value parameter & noexcept

雨燕双飞 提交于 2019-11-29 11:09:10
问题 In this example code: explicit MyClass(std::wstring text) noexcept; Is the use of noexcept here correct? wstring can potentially throw on construction but does the throw happen before we are in the constructor or while we are in the constructor? EDIT: Suppose this can be generalised to any function taking a by-value parameter. 回答1: The construction and destruction of function parameters happens in the context of the caller. So no, if the construction of text throws, that is not a violation of

Noexcept and copy, move constructors

淺唱寂寞╮ 提交于 2019-11-29 09:29:35
问题 Everywhere I look it seems to be the agreement that the standard library must call copy constructors instead of move constructors when the move constructor is noexcept(false). Now I do not understand why this is the case. And futher more Visual Studio VC v140 and gcc v 4.9.2 seems to do this differently. I do not understand why noexcept this is a concern of e.g. vector. I mean how should vector::resize() be able to give strong exception guarantee if T does not. As I see it the exception level