<p dir="ltr">Please note this on the bug report</p>
<br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 11, 2017, 13:46 Dimitry Andric <<a href="mailto:dimitry@andric.com">dimitry@andric.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The shortest reduction I could come up with is this:<br>
<br>
template <bool> struct a;<br>
template <class> struct B {};<br>
template <class b, bool = B<b>::f> struct g;<br>
template <class c, class, int = g<c>::f> struct i;<br>
template <class> class j {<br>
public:<br>
j();<br>
template <class d> j(j<d>, typename a<i<d *, int *>::f>::e = int());<br>
};<br>
struct k {<br>
k() noexcept = default;<br>
k(k &) = default;<br>
j<int> h{};<br>
};<br>
<br>
All versions of g++ that I tried compile this without error, while clang says:<br>
<br>
testcase.cpp:11:3: error: default member initializer for 'h' needed within definition of enclosing class 'k' outside of member functions<br>
k() noexcept = default;<br>
^<br>
testcase.cpp:3:27: note: in instantiation of template class 'B<int *>' requested here<br>
template <class b, bool = B<b>::f> struct g;<br>
^<br>
testcase.cpp:4:33: note: in instantiation of default argument for 'g<int *>' required here<br>
template <class c, class, int = g<c>::f> struct i;<br>
^~~~<br>
testcase.cpp:8:41: note: in instantiation of default argument for 'i<int *, int *>' required here<br>
template <class d> j(j<d>, typename a<i<d *, int *>::f>::e = int());<br>
^~~~~~~~~~~~~<br>
testcase.cpp:5:24: note: while substituting deduced template arguments into function template 'j' [with d = int]<br>
template <class> class j {<br>
^<br>
testcase.cpp:13:10: note: default member initializer declared here<br>
j<int> h{};<br>
^<br>
1 error generated.<br>
<br>
-Dimitry<br>
<br>
> On 11 Jul 2017, at 16:54, Joe Sylve <<a href="mailto:joe.sylve@gmail.com" target="_blank">joe.sylve@gmail.com</a>> wrote:<br>
><br>
> It is, but I'm not sure that libc++ is the cause or just points out the bug. If you look at the stack overflow link, you'll see an example of different code that triggers a similar error without the use of any library stuff.<br>
><br>
><br>
> On Tue, Jul 11, 2017, 03:45 Dimitry Andric <<a href="mailto:dimitry@andric.com" target="_blank">dimitry@andric.com</a>> wrote:<br>
> FYI, this looks like an issue in libc++. If I compile your sample with the latest and greatest clang, but point it to the g++ 7.1.1 libstdc++ headers, it works just fine.<br>
><br>
> -Dimitry<br>
><br>
>> On 10 Jul 2017, at 20:55, Joe Sylve via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>> I'm seeing an error that is similar to the question raised at <a href="https://stackoverflow.com/questions/43819314" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/43819314</a>. That question seems to not have any consensus as to what the problem may be.<br>
>><br>
>> I would appreciate if someone could shed some light on my issue and let me know if this is a known compiler bug or if clang is working as intended.<br>
>><br>
>> The following code produces a compile-time error in clang++ 4.0.0 and later, but works fine in gcc as well as previous versions of clang.<br>
>><br>
>> #include <memory><br>
>><br>
>> struct A {<br>
>> A() noexcept = default;<br>
>> A(const A&) noexcept = default;<br>
>><br>
>> std::shared_ptr<int> _a {};<br>
>> };<br>
>><br>
>> int main() {<br>
>> return 0;<br>
>> }<br>
>><br>
>> It's worth noting that if I remove the copy constructor, this compiles fine. If I remove the noexcept qualification from the default constructor it also compiles fine.<br>
>><br>
>> The error I'm getting is as follows:<br>
>><br>
>> <source>:4:5: error: default member initializer for '_a' needed within definition of enclosing class 'A' outside of member functions<br>
>> A() noexcept = default;<br>
>> ^<br>
>> /opt/compiler-explorer/clang-4.0.0/bin/../include/c++/v1/type_traits:1306:29: note: in instantiation of template class 'std::__1::is_class<int *>' requested here<br>
>> template <class _Tp, bool = is_class<_Tp>::value><br>
>> ^<br>
>> /opt/compiler-explorer/clang-4.0.0/bin/../include/c++/v1/type_traits:1311:71: note: in instantiation of default argument for '__libcpp_abstract<int *>' required here<br>
>> template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract : public __libcpp_abstract<_Tp> {};<br>
>> ^~~~~~~~~~~~~~~~~~~~~~<br>
>> /opt/compiler-explorer/clang-4.0.0/bin/../include/c++/v1/type_traits:1384:39: note: in instantiation of template class 'std::__1::is_abstract<int *>' requested here<br>
>> !is_abstract<_T2>::value> {};<br>
>> ^<br>
>> /opt/compiler-explorer/clang-4.0.0/bin/../include/c++/v1/memory:3918:39: note: in instantiation of template class 'std::__1::is_convertible<int *, int *>' requested here<br>
>> typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())<br>
>> ^<br>
>> /opt/compiler-explorer/clang-4.0.0/bin/../include/c++/v1/memory:3883:28: note: while substituting deduced template arguments into function template 'shared_ptr' [with _Yp = int]<br>
>> class _LIBCPP_TEMPLATE_VIS shared_ptr<br>
>> ^<br>
>> <source>:7:26: note: default member initializer declared here<br>
>> std::shared_ptr<int> _a {};<br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
><br>
<br>
</blockquote></div>