Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

initializer_list

34 views
Skip to first unread message

Daniel

unread,
Jul 27, 2016, 7:33:23 AM7/27/16
to
Consider

struct Q {
Q() = default;
Q(Q const&) { std::cout << "copy-constructor" << std::endl; }
Q(std::initializer_list<Q>) { std::cout << "initializer_list constructor"
<< std::endl; }
};

int main() {
Q q;
Q q2 = Q{ q };
}

which is an example taken from
http://en.cppreference.com/w/cpp/language/list_initialization, in the Notes
section.

According to cppreference, the initializer-list constructor (not copy
constructor), should be called.

But with Visual C++ 2015 Update 3, it is the copy constructor that is called.

Which is right?

Thanks,
Daniel

Öö Tiib

unread,
Jul 27, 2016, 10:32:06 AM7/27/16
to
Avoid relying on side effects of such list-move-copy-constructors since
behavior in standard (and so in compilers) may change on patch-to-patch
level for some time. I think the committee is trying really hard to make the
initialization to work. It may be is possible but it will take time.

The particular behavior of MSVC that you describe seems to be most likely
conforming with fix of a defect #1467 of standard:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1467

The resulting unclarity that you complain about it already opened as issue
#2137.
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2137

IOW the outcome that you describe may be is unintended result of given
fix and so subject of further changes or not but MSVC seems to conform
in some sense right now. ;-)

Daniel

unread,
Jul 27, 2016, 3:57:13 PM7/27/16
to
On Wednesday, July 27, 2016 at 10:32:06 AM UTC-4, Öö Tiib wrote:
>
> The resulting unclarity that you complain about it already opened as issue
> #2137.
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2137
>
> IOW the outcome that you describe may be is unintended result of given
> fix and so subject of further changes or not but MSVC seems to conform
> in some sense right now. ;-)

Thanks. I share the concerns of the author of issue #2137.

Daniel

0 new messages