<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;">
<div>== Summary ==</div>
<div><br>
</div>
<div>In clang 3.7, overload resolution between an initializer-list constructor and a copy constructor favors the copy constructor. The standard seems to specify that explicit initializer-list constructors take precedence in overload resolution. This behavior
 is different from clang 3.6 and from all versions of gcc. This behavior is not observed when the overload resolution is between an initializer-list constructor and a non-copy constructor.</div>
<div><br>
</div>
<div>This was encountered when converting a recursive tree-like type from gcc to clang. The tree-like type could accept an initializer-list of children, but passing a single child would invoke the copy constructor instead.</div>
<div><br>
</div>
<div><br>
</div>
<div>== Minimal code example: ==</div>
<div><br>
</div>
<div>
<div>#include <initializer_list></div>
<div>struct T {</div>
<div>  int x;</div>
<div>  T() : x(0) {}</div>
<div>  T(const T&) : x(1) {}</div>
<div>  T(std::initializer_list<T>) : x(2) {}</div>
<div>};</div>
<div>int foo() {</div>
<div>  T t1;</div>
<div>  T t2 = { t1 };</div>
<div>  return t2.x;</div>
<div>}</div>
</div>
<div><br>
</div>
<div>In clang 3.7, foo() returns 1. In clang 3.6 and all versions of gcc, foo() returns 2.</div>
<div>The overload resolution in clang 3.7 is consistent with clang 3.6 and gcc when a non-copy constructor is involved; the following example returns 4 on all tested compilers.</div>
<div><br>
</div>
<div>
<div>#include <initializer_list></div>
<div>struct T {</div>
<div>  int x;</div>
<div>  T(int) : x(3) {}</div>
<div>  T(std::initializer_list<int>) : x(4) {}</div>
<div>};</div>
<div>int foo() {</div>
<div>  T t = { 7 };</div>
<div>  return t.x;</div>
<div>}</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>== Standard references (n3936): ==</div>
<div><br>
</div>
<div>- 8.5.4 "List-initialization"</div>
<div>- 13.3.1.7, "Initialization by list-initialization"</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Regards,</div>
<div>Nicholas</div>
</body>
</html>