Topic: preconditions and exceptions
Author: Al Grant <algrant@myrealbox.com>
Date: Thu, 28 Jan 2010 10:59:38 CST Raw View
23.3.5.2 std::bitset::test() says
Requires: pos is valid
Throws: out_of_range if pos does not correspond to a valid bit
position
This is self-contradictory. It first says that it's not valid
to call the function with an invalid position, but then gives
perfectly well-defined behavior if you do.
Compare operator[] where the precondition makes sense,
as the behavior when out of range is not specified.
Is this a defect? Should test() not have a precondition?
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Thu, 28 Jan 2010 17:09:57 CST Raw View
On 28 Jan., 17:59, Al Grant <algr...@myrealbox.com> wrote:
> 23.3.5.2 std::bitset::test() says
> Requires: pos is valid
> Throws: out_of_range if pos does not correspond to a valid bit
> position
>
> This is self-contradictory. It first says that it's not valid
> to call the function with an invalid position, but then gives
> perfectly well-defined behavior if you do.
>
> Compare operator[] where the precondition makes sense,
> as the behavior when out of range is not specified.
>
> Is this a defect? Should test() not have a precondition?
This has been debated in:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#529
This issue has been closed as NAD Editorial with the remark
"General agreement that precondition violations are synonymous with
UB"
so until any further normative wording is added to the standard
that would make this statement invalid it seems valid to assume
that the above Requires: element is moot and should be removed
as part of editorial work.
HTH & Greetings from Bremen,
Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]