Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <c2d54cdf-48ca-41f1-9652-ab00f4c8ea04@googlegroups.com> (permalink) |
|---|---|
| Newsgroups | comp.std.c++ |
| From | s.scott.schurr@googlemail.com |
| Subject | Throwing in a constexpr function in C++14 |
| Organization | unknown |
| Date | 2013-10-18 01:07 -0600 |
Hi C++ language lawyers,
I've hunted through the C++11 and pre-C++14 standards looking for
where they say that it is okay to put a throw in a constexpr function
or constructor as long as the throw is in an unevaluated part of the
code.
I believe that I've found the sentence in the C++11 FDIS (N3242)
that allows the constexpr throw pattern. In Section 5.19 (Constant
Expressions) paragraph 2 it says:
A conditional-expression is a constant expression unless it involves
one of the following as a potentially evaluated subexpression (3.2),
but subexpressions of logical AND (5.14), logical OR (5.15), and
conditional (5.16) operations that are not evaluated are not
considered...
The C++11 FDIS further reinforces the idiom with an example in Section
7.1.5 (The constexpr Specifier) paragraph 5...
constexpr int f(bool b)
{ return b ? throw 0 : 0; } // OK
Now I'm looking for similar text in N3691 which is, I believe, a
recent preliminary version of the C++14 standard.
I know that rules for constexpr are being expanded in C++14. But
I'm expecting that the pattern of putting an unevaluated throw in
a constexpr function as a way of error handling will still be
supported in C++14. I see that the throwing example in Section
7.1.5 (The constexpr Specifier) paragraph 5 is still present in
N3691.
But I haven't yet located any text in N3691 comparable to the text I
found in Section 5.19 (Constant Expressions) paragraph 2 of the C++11
FDIS.
The most likely case is that the necessary C++14 text is there but
I missed it. But possibly the text is missing intentionally.
Perhaps the constexpr throw pattern is one of those things that one
must infer from what the standard doesn't say. Least likely, but
within the realm of possibility, is that the text is unintentionally
missing and needs to be added.
Are there any suggestions for how I should read the preliminary
C++14 standard on this subject? References to paragraphs are
especially appreciated.
Thanks for your guidance.
SSchurr
--
[ 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 — Next in thread | Find similar
Throwing in a constexpr function in C++14 s.scott.schurr@googlemail.com - 2013-10-18 01:07 -0600 Re: Throwing in a constexpr function in C++14 Daniel Krügler <daniel.kruegler@googlemail.com> - 2013-10-19 11:04 -0700
csiph-web