Visual C++ 2013 RTM (with Update 1) Initializer List Bug - by lluo

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


4
0
Sign in
to vote
ID 815949 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 1/28/2014 12:55:50 PM
Access Restriction Public

Description

Hi Visual C++ team,

The Visual C++ 12 RMT (Update 1) compiler could not compile the following code (while it builds and runs perfectly fine under Clang/GCC), with the error message:

1>c:\projects\initializerlist\initializerlist.cpp(28): error C2440: 'initializing' : cannot convert from 'initializer-list' to 'std::list<Element,std::allocator<_Ty>>'
1>          with
1>          [
1>              _Ty=Element
1>          ]
1>          No constructor could take the source type, or constructor overload resolution was ambiguous

<code>

#include <string>
#include <list>
#include <unordered_map>

typedef std::string String;

struct Element
{
    String name;

    typedef std::unordered_map<String, String> Attributes;
    Attributes attributes;

    typedef std::list<Element> Elements;
    Elements children;
};

// Simple form, which doesn't compile
Element::Elements children =  {
    { "X", { {"min", "-1"}, {"max", "1"} } },
    { "Y", { {"min", "-1"}, {"max", "1"} } },
    { "Z", { {"min", "-1"}, {"max", "1"} } },
};

// A more exotic form (nested initialization), which doesn't compile of course
Element::Elements elements = { { "name", { {"attr0", "val0"}, {"attr1", "val1"} }, {
    { "X", { {"min", "-1"}, {"max", "1"} } },
    { "Y", { {"min", "-1"}, {"max", "1"} } },
    { "Z", { {"min", "-1"}, {"max", "1"} } },
} } };

<code/>

I tried the alternative form below that makes the code compile, but the program hit an assertion (list iterator incompatible):

Element::Elements children =  {
    { "X", { std::make_pair("min", "-1"), std::make_pair("max", "1") } },
    { "Y", { std::make_pair("min", "-1"), std::make_pair("max", "1") } },
    { "Z", { std::make_pair("min", "-1"), std::make_pair("max", "1") } },
};

I hope this bug is going to be fixed in Visual C++ 2013 Update 2.

Thanks,

Lin
Sign in to post a comment.
Posted by lluo on 11/12/2014 at 4:59 PM
I can confirm that this issue seems to be fixed in VS2013 update 3 as well as VS2015 Preview.

Thanks!
Posted by Microsoft on 11/12/2014 at 1:08 PM
Hi:
    Thanks for reporting the issue.
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next major release of Visual C++.

Xiang Yan
Visual C++ Team
Posted by lluo on 2/28/2014 at 10:33 AM
Is this confirmed as a compiler bug? Or else?
Posted by Microsoft on 1/28/2014 at 10:53 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 1/28/2014 at 1:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)