[llvm-bugs] [Bug 28559] iter_swap() shouldn't have an exception specification

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 1 22:49:11 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=28559

Eric Fiselier <eric at efcs.ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #7 from Eric Fiselier <eric at efcs.ca> ---
Your iter_swap overload doesn't meet the requirements of C++1z [alg.swap]/p5:

>   template<class ForwardIterator1, class ForwardIterator2>
>     void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
> Requires: a and b shall be dereferenceable. *a shall be swappable 
> with (20.5.3.2) *b.

That requires your IntProxy type to be swappable, which it is not. violating
the function preconditions, and according to [res.on.required]:

> Violation of the preconditions specified in a function’s
> Requires: paragraph results in undefined behavior
> unless the function’s Throws: paragraph specifies throwing
> an exception when  the precondition is violated.

Additionally your specialization is not immune to the requirements specified in
the standard. See [namespace.std]

> A program may add a template specialization for any standard library
> template to namespace std only if [...] the specialization meets the 
> standard library requirements for the original template and is not 
> explicitly prohibited.

In summary your example has undefined behavior because IntProxy type returned
from the iterator isn't swappable and that violates the requirements for
iter_swap.

Feel free to reopen if you disagree or if I was unclear.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170302/d462e18a/attachment.html>


More information about the llvm-bugs mailing list