<div dir="ltr">Yeah, fair - does seem buggy.<br><br>Here's a simpler example at least:<br><br><font face="monospace">extern void unknown();<br>template <typename T><br>struct C {<br> ~C() {}<br>};<br>union U {<br> explicit U() : ci() { unknown(); }<br> ~U() {}<br> C<int> ci; // destructor C<int>::~C() not generated<br>};<br>int main() {<br> U u;<br>}</font><br><br>With 'unknown' defined in another translation unit.</div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 30, 2021 at 5:50 AM Nathan Sidwell via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 4/28/21 9:55 PM, Riyaz Puthiyapurayil via cfe-dev wrote:<br>
> The following test case fails to compile with clang++ because it does <br>
> not generate code for a destructor (as indicated below). Is this a bug <br>
> or am I missing something? Gcc works fine.<br>
<br>
smells like a bug.<br>
<br>
> <br>
> Wandbox permlink: <a href="https://wandbox.org/permlink/H7BcjQzXwoqZclj3" rel="noreferrer" target="_blank">https://wandbox.org/permlink/H7BcjQzXwoqZclj3</a> <br>
> <<a href="https://wandbox.org/permlink/H7BcjQzXwoqZclj3" rel="noreferrer" target="_blank">https://wandbox.org/permlink/H7BcjQzXwoqZclj3</a>><br>
> <br>
> // prog.cpp<br>
> <br>
> #include "D.h"<br>
> <br>
> D *f(char c) {<br>
> <br>
> return c ? new D(c) : new D(-1);<br>
> <br>
> }<br>
> <br>
> D *x;<br>
> <br>
> int main() {<br>
> <br>
> x = f('a');<br>
> <br>
> return 0;<br>
> <br>
> }<br>
> <br>
> // D.h<br>
> <br>
> #ifndef D_H<br>
> <br>
> #define D_H<br>
> <br>
> extern void unknown();<br>
> <br>
> template<typename T><br>
> <br>
> class C {<br>
> <br>
> T t;<br>
> <br>
> public:<br>
> <br>
> explicit C(T t_) : t(t_) {}<br>
> <br>
> ~C() {}<br>
> <br>
> };<br>
> <br>
> class D {<br>
> <br>
> union U<br>
> <br>
> {<br>
> <br>
> explicit U(int i) : ci(i) { unknown(); }<br>
> <br>
> explicit U(char c) : cc(c) {}<br>
> <br>
> ~U() {}<br>
> <br>
> C<int> ci; // destructor C<int>::~C() not generated<br>
> <br>
> C<char> cc;<br>
> <br>
> };<br>
> <br>
> U u;<br>
> <br>
> bool uIsInt;<br>
> <br>
> public:<br>
> <br>
> explicit D(int i) : u(i), uIsInt(true) {}<br>
> <br>
> explicit D(char c) : u(c), uIsInt(false) {}<br>
> <br>
> ~D(); // explicit destruction of u<br>
> <br>
> };<br>
> <br>
> D* f(char c);<br>
> <br>
> #endif // D_H<br>
> <br>
> // unk.cpp<br>
> <br>
> #include "D.h"<br>
> <br>
> void unknown() {}<br>
> <br>
> D::~D() {<br>
> <br>
> if (uIsInt)<br>
> <br>
> u.ci.~C();<br>
> <br>
> else<br>
> <br>
> u.cc.~C();<br>
> <br>
> }<br>
> <br>
> $ clang++ prog.cpp unk.cpp<br>
> <br>
> /tmp/prog-bfa5e6.o: In function `D::U::U(int)':<br>
> <br>
> prog.cc:(.text._ZN1D1UC2Ei[_ZN1D1UC2Ei]+0x3e): undefined reference to <br>
> `C<int>::~C()'<br>
> <br>
> clang-11: error: linker command failed with exit code 1 (use -v to see <br>
> invocation)<br>
> <br>
> <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="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
> <br>
<br>
<br>
-- <br>
Nathan Sidwell<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>