Ouch.<div><br></div><div>This isn't restricted to non-static member initializers, it's a problem with the way we instantiate direct-list-initialization in general:<div><br><div>#include <atomic></div><div>template<typename> struct X {</div>
<div>  int f() {</div><div>    std::atomic<int> v{0};</div><div>    return v;</div><div>  }</div><div>};</div><div>int k = X<int>().f();</div><div><br></div><div><div><stdin>:4:22: error: copying variable of type 'std::atomic<int>' invokes deleted constructor</div>
<div>    std::atomic<int> v{0};</div><div>                     ^ ~</div><div><stdin>:8:18: note: in instantiation of member function 'X<int>::f' requested here</div><div>int k = X<int>().f();</div>
<div>                 ^</div><div>[...]</div><br><div class="gmail_quote">On Thu, Jul 26, 2012 at 12:30 PM, Howard Hinnant <span dir="ltr"><<a href="mailto:hhinnant@apple.com" target="_blank">hhinnant@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This looks wrong to me.  Is this a known bug?<br>
<br>
#include <atomic><br>
<br>
//<br>
// This class can compile<br>
//<br>
class Working<br>
{<br>
private:<br>
    std::atomic<int> value_{0};<br>
};<br>
<br>
//<br>
// This class cannot compile<br>
//<br>
template <typename Ty1><br>
class NotWorking<br>
{<br>
    private:<br>
        std::atomic<int> value_{0}; // <---- error here<br>
};<br>
<br>
int main()<br>
{<br>
    Working working;<br>
    NotWorking<int> not_working;<br>
}<br>
<br>
test.cpp:19:33: error: copying member subobject of type 'std::atomic<int>' invokes deleted constructor<br>
        std::atomic<int> value_{0}; // <---- error here<br>
                                ^<br>
test.cpp:25:21: note: in instantiation of template class 'NotWorking<int>' requested here<br>
    NotWorking<int> not_working;<br>
                    ^<br>
/Users/hhinnant/Development/temp_libcxx/include/atomic:721:7: note: copy constructor of 'atomic<int>' is implicitly deleted because base class<br>
      '__atomic_base<int>' has a deleted copy constructor<br>
    : public __atomic_base<_Tp><br>
      ^<br>
/Users/hhinnant/Development/temp_libcxx/include/atomic:640:7: note: copy constructor of '__atomic_base<int, true>' is implicitly deleted because base class<br>
      '__atomic_base<int, false>' has a deleted copy constructor<br>
    : public __atomic_base<_Tp, false><br>
      ^<br>
/Users/hhinnant/Development/temp_libcxx/include/atomic:625:5: note: function has been explicitly marked deleted here<br>
    __atomic_base(const __atomic_base&) = delete;<br>
    ^<br>
1 error generated.<br>
<br>
Thanks,<br>
Howard<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div></div>