[cfe-dev] (libc++) Implicit type converstion, value initialization and initializer lists
Andrew Parker
andrew.j.c.parker at gmail.com
Mon Jul 13 21:20:41 PDT 2015
I picked up an assert in a libc++ test with MSVC and am unsure whether
actually MSVC is actually performing as per the standard in this case.
The test is:
std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp
The code in question is:
* typedef int T;*
* typedef std::forward_list<T> C;*
* typedef C::iterator I;*
* C c;*
* I i = c.insert_after(c.cbefore_begin(), {});*
* assert(i == c.before_begin());*
The intention is that calling insert_after with an empty initializer list
will insert nothing, hence the assert criterion. However, empty
initializers for *int* should be subject to value initialization, i.e. {}
should be interpreted as int i{};. So should this call not be equivalent
to:
*I i = c.insert_after(c.cbefore_begin(), 0);?*
MSVC compiles the code in this way, i.e.
*iterator **insert_after(const_iterator __p, value_type&& __v){...}*
is called instead of
*iterator insert_after(const_iterator __p, initializer_list<value_type>
__il){...}*
hence the list grows by one in size.
My guess would be that MSVC is doing the wrong thing, as this is usually
the case. However, I can't be certain in this case so appeal to the
experts on this. If MSVC is correct then this actually points to a clang
bug not a libc++ one.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150714/4cf22369/attachment.html>
More information about the cfe-dev
mailing list