Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <ip6e5a$4gi$1@dont-email.me> (permalink) |
|---|---|
| Newsgroups | comp.std.c++ |
| From | Daniel Krügler <daniel.kruegler@googlemail.com> |
| Subject | Re: noexcept-specification vs returning a prvalue |
| Organization | A noiseless patient Spider |
| References | <83f4aba6-91b5-4c95-b298-46cc269651ee@r23g2000vbp.googlegroups.com> |
| Date | 2011-04-26 11:05 -0600 |
On 2011-04-23 18:21, Nikolay Ivchenkov wrote:
>
> Consider the following example:
>
> #include<iostream>
>
> struct C
> {
> C();
> C(C const&) noexcept(false);
> };
>
> C f() noexcept(true);
>
> int main()
> {
> std::cout<< (int)noexcept(f());
> }
>
> Here f is declared with non-throwing exception-specification, though
> copy constructor of its return type does not have non-throwing
> exception-specification. What is the value of expression noexcept(f())?
I think the FDIS says that noexcept(f()) shall evaluate to "true" in
this example. My interpretation is based on the way how I read the
meaning of "A function is said to allow" in [except.spec] p. 8
(complemented by p. 12) to refer to exceptions that are possibly
invoked by the function implementation including its return statement.
The return statement includes the construction and possible move/copy
of the return value of f() as explained in [stmt.return] p. 2:
"A return statement can involve the construction and copy or move of a
temporary object (12.2)."
so the tagging of f with noexcept(true) means that we are sure that
the function call including the construction and possible copy [move
is not possible here] of the return value) does no throw an exception.
It seems to me that this does not include the destruction of the
temporary, so extending the definition of C like
struct C
{
C();
C(C const&) noexcept(false);
~C noexcept(false);
};
should change the value of noexcept(f()) to false, because the
noexcept operator also considers the destruction of the temporary of
the complete function call expression.
It could be helpful, if [except.spec] p. 8 and/or p. 12 would be
clearer in this regard.
HTH & Greetings from Bremen,
Daniel Krügler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
noexcept-specification vs returning a prvalue Nikolay Ivchenkov <tsoae@mail.ru> - 2011-04-23 10:21 -0600
Re: noexcept-specification vs returning a prvalue Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-04-26 11:05 -0600
Re: noexcept-specification vs returning a prvalue Johannes Schaub<schaub.johannes@googlemail.com> - 2011-04-27 10:51 -0600
Re: noexcept-specification vs returning a prvalue Johannes Schaub <schaub.johannes@googlemail.com> - 2011-04-26 11:04 -0600
csiph-web