Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Tue, 26 Apr 2011 11:10:11 -0500 |
| Return-Path | <cppmods@mcgurn.dreamhost.com> |
| Sender | std-cpp-request@vandevoorde.com |
| Approved | james.dennett@gmail.com |
| Message-ID | <4db5b2ce$0$6764$9b4e6d93@newsspool3.arcor-online.net> (permalink) |
| Newsgroups | comp.std.c++ |
| From | Johannes Schaub <schaub.johannes@googlemail.com> |
| Reply-To | schaub.johannes@googlemail.com |
| Followup-To | comp.std.c++ |
| Subject | Re: noexcept-specification vs returning a prvalue |
| Organization | Arcor |
| References | <83f4aba6-91b5-4c95-b298-46cc269651ee@r23g2000vbp.googlegroups.com> |
| Content-Type | text/plain; charset="ISO-8859-1" |
| X-Original-Date | Mon, 25 Apr 2011 19:43:51 +0200 |
| X-Submission-Address | std-c++-submit@vandevoorde.com |
| To | undisclosed-recipients:; |
| Date | Tue, 26 Apr 2011 11:04:50 CST |
| Lines | 57 |
| X-Usenet-Provider | http://www.giganews.com |
| X-Trace | sv3-Pk8kZ+G5c+HrUVeJWlFjhPdxbGqOCHDaD/YhIHnf8h79UG6UpXlwlWWotPFR24qxUjY8gJGvG6BJZX6!kNnDNcALgZyNIi2f0JvkfZZR5vzH/izND1CnVURlDOV8+c8sH19QErtBAyyUHc8YmPYmA2WO/gtE!amfjB5+WQQ== |
| X-Complaints-To | abuse@giganews.com |
| X-DMCA-Notifications | http://www.giganews.com/info/dmca.html |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3192 |
| Xref | x330-a1.tempe.blueboxinc.net comp.std.c++:128 |
Followups directed to: comp.std.c++
Show key headers only | View raw
(second submission attempt after 48h).
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())?
>
The value is "true", and calling "f" results in a call to std::terminate if
the copy consructor of C actually throws.
I would say the author of "f" needs to make sure its return type either is
nothrow-copyable, or that all constructions it does by returning will not
throw.
In addition, this is not tied to the copy constructor, I think. The
following would be fine if "f"'s author knows that C's default construtor
would no throw, too:
C f() noexcept(true) { return {}; /* note: no copy! */ }
Note that any implicit call to the copy constructor of "C" for a return
statement has to occur in the context of the caller. So to the noexcept
operator, it does not make a difference whether or not the copy constructor
has a throwing exception spec.
If C has a potentially throwing dtor, that makes a difference though,
because the dtor is invoked in the context of the caller (the noexcept test-
expression).
--
[ 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 | 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